Go Lang Installation and Visual Studio Code configuration.
Here are the installation steps for Go on Windows, macOS, and Linux along with configuring Go in VSCode:
Installing Go on Windows
Download the latest Go installer for Windows from the official website: golang.org/dl
Run the installer and follow the instructions.
After installation, open Command Prompt or PowerShell and type the following command to verify that Go is installed correctly:
go version
If Go is installed correctly, you should see the version number printed in the terminal.
Next, set up the GOPATH environment variable. This variable specifies the location of your Go workspace, which is where you will store your Go projects and packages. To set up the GOPATH variable, follow these steps:
Open the Start menu and search for "Environment Variables."
Click "Edit the system environment variables."
Click "Environment Variables."
Under "System Variables," click "New" and add the following:
Variable name: GOPATH
Variable value: C:\Users\YourUserName\go
Replace "YourUserName" with your actual username.
Finally, install the Go extension in VSCode by going to the extensions marketplace and searching for "Go." Click "Install" and then reload VSCode.
Installing Go on macOS/OSX
Download the latest Go installer for macOS from the official website: golang.org/dl
Run the installer and follow the instructions.
After installation, open Terminal and type the following command to verify that Go is installed correctly:
go version
If Go is installed correctly, you should see the version number printed in the terminal.
Next, set up the GOPATH environment variable. This variable specifies the location of your Go workspace, which is where you will store your Go projects and packages. To set up the GOPATH variable, follow these steps:
Open Terminal and type the following command:
nano ~/.bash_profile
This will open the .bash_profile file in the Nano text editor.
Add the following line to the file
export GOPATH=$HOME/go
Save the file and exit Nano by pressing "Control + X" and then "Y" and "Enter."
Finally, run the following command to reload your .bash_profile:
source ~/.bash_profile
Finally, install the Go extension in VSCode by going to the extensions marketplace and searching for "Go." Click "Install" and then reload VSCode.
Installing Go on Linux
Download the latest Go binary archive for Linux from the official website (golang.org/dl).
Extract the downloaded archive to
/usr/local
using the following command:
sudo tar -C /usr/local -xzf go<version>.linux-<architecture>.tar.gz
Replace <version>
and <architecture>
with the appropriate values for your system. 3. Add the Go binary directory to your PATH
environment variable by adding the following line to your ~/.profile
or ~/.bashrc
file:
export PATH=$PATH:/usr/local/go/bin
- Once the installation is complete, open the terminal and type
go version
to verify that Go is installed.
Configuring Go on VSCode
Install the Go extension for VSCode by clicking on the Extensions icon in the left sidebar, searching for "Go" and clicking Install.
Once the extension is installed, open the Settings tab in VSCode by clicking on the gear icon in the bottom left corner and selecting "Settings".
In the search bar, type "go.gopath" and set the value to the directory where you will store your Go projects. This is where Go will look for packages and dependencies.
In the search bar, type "go.toolsGopath" and set the value to the same directory as the "go.gopath" setting. This is where Go will store its tools and binaries.
Close the Settings tab and create a new folder for your Go project.
Open the new folder in VSCode and create a new file called "main.go".
Add the following code to the "main.go" file:
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
- Save the file and press F5 to run the code. You should see "Hello, world!" printed on the terminal.
That's it! You should now be able to use Go on VSCode.
I hope this helps, you!!
More such articles:
https://www.youtube.com/channel/UCiTaHm1AYqMS4F4L9zyO7qA
\==========================**=========================
If this article adds any value to you then please clap and comment.
Let’s connect on Stackoverflow, LinkedIn, & Twitter.