Setting up the Go programming environment involves installing the Go compiler and configuring your system to recognize Go-related commands. Below are step-by-step instructions for installing Go on Linux/Ubuntu, MacOS, and Windows.
Linux/Ubuntu:
Download Go: Open a terminal and run the following command to download the latest stable version of Go:
sudo apt update sudo apt install golang
Set Go Environment Variables: Add the following lines to your shell profile file (e.g.,
~/.bashrc
or~/.zshrc
):export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin export PATH=$PATH:/usr/local/go/bin
Then, reload your profile:
source ~/.bashrc # or source ~/.zshrc
Verify Installation: Verify the Go installation by running:
go version
go version
MacOS:
Download Go: Install Go on MacOS using Homebrew. If Homebrew is not installed, you can install it from https://brew.sh/. Once Homebrew is installed, run:
brew install go
Set Go Environment Variables: Add the following lines to your shell profile file (e.g.,
~/.bash_profile
or~/.zshrc
):export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin export PATH=$PATH:/usr/local/go/bin
Then, reload your profile:
source ~/.bash_profile # or source ~/.zshrc
Verify Installation: Verify the Go installation by running:
go version
Windows:
Download and Install:
Download the MSI installer for Windows from the official Go website: https://golang.org/dl/
Run the installer and follow the on-screen instructions.
Set Environment Variables:
Right-click on "This PC" or "Computer" and select "Properties."
Click on "Advanced system settings."
Click on the "Environment Variables..." button.
Under "System variables," click on "New" and add a new variable:
Variable name:
GOPATH
Variable value:
C:\Users\YourUsername\go
(ReplaceYourUsername
with your actual username.)
Edit the
Path
variable and add the following to the end:C:\Go\bin
(or the path where Go is installed)
Verify Installation: Open a new Command Prompt and run:
go version
These steps should help you set up Go on your Linux/Ubuntu, MacOS, or Windows system. Remember to replace any specific paths or usernames with your actual system information. Once installed, you're ready to start writing and running Go programs!