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

  1. Download the latest Go installer for Windows from the official website: golang.org/dl

  2. Run the installer and follow the instructions.

  3. After installation, open Command Prompt or PowerShell and type the following command to verify that Go is installed correctly:

go version
  1. If Go is installed correctly, you should see the version number printed in the terminal.

  2. 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.

  3. 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

  1. Download the latest Go installer for macOS from the official website: golang.org/dl

  2. Run the installer and follow the instructions.

  3. After installation, open Terminal and type the following command to verify that Go is installed correctly:

     go version
    
  4. If Go is installed correctly, you should see the version number printed in the terminal.

  5. 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

  1. Download the latest Go binary archive for Linux from the official website (golang.org/dl).

  2. 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
  1. Once the installation is complete, open the terminal and type go version to verify that Go is installed.

Configuring Go on VSCode

  1. Install the Go extension for VSCode by clicking on the Extensions icon in the left sidebar, searching for "Go" and clicking Install.

  2. 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".

  3. 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.

  4. 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.

  5. Close the Settings tab and create a new folder for your Go project.

  6. Open the new folder in VSCode and create a new file called "main.go".

  7. Add the following code to the "main.go" file:

    package main

    import "fmt"

    func main() {
        fmt.Println("Hello, world!")
    }
  1. 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://medium.com/techwasti

https://www.youtube.com/channel/UCiTaHm1AYqMS4F4L9zyO7qA

https://www.techwasti.com/

\==========================**=========================

If this article adds any value to you then please clap and comment.

Let’s connect on Stackoverflow, LinkedIn, & Twitter.

Did you find this article valuable?

Support techwasti by becoming a sponsor. Any amount is appreciated!