Go Installation Guide
Go is an open-source programming language developed by Google that makes it easy to build simple, reliable, and efficient software.
Tested on macOS Sonoma 14.0
THIS PAGE IS CURRENTLY UNDER CONSTRUCTION
Install Go
Go is an open-source programming language developed by Google. Follow the steps below to install Go on macOS:
Step 1: Install Homebrew
If you don't have Homebrew installed, follow the instructions provided on the Homebrew website (opens in a new tab).
How to Install Homebrew on macOSIf you already have Homebrew installed on your macOS, you can skip this step.
Step 2: Install Go with Homebrew
Once Homebrew is installed, run the following command to install the latest version of Go:
brew install goDo you want to install a specific version of Go?
To install a specific version of Go using Homebrew, you can use the following steps:
-
Check Available Versions:
shbrew search goThis command lists all the available versions of Go that can be installed via Homebrew.
-
Install a Specific Version: Once you've identified the version you want to install, use the following command:
brew install go@<version>Replace
<version>with the specific version number (e.g.,1.16,1.17, etc.). -
Link the Installed Version: By default, Homebrew will not link this version to the system
PATHto avoid conflicts. To use the installed version, you need to link it manually:shbrew link --force --overwrite go@<version>This command ensures that the specified version of Go is set as the default version in your terminal.
-
Set Up Environment Variables: You might need to update your environment variables to ensure your shell recognizes the new version. Add the following lines to your shell configuration file (
.bashrc,.zshrc, etc.):~/.zshrcexport PATH="/usr/local/opt/go@<version>/bin:$PATH"Again, replace
<version>with the specific version number you installed. -
Verify Installation: To confirm that the installation was successful and that the correct version of Go is being used, run:
shgo versionThis command should display the version of Go you just installed.
-
Switching Between Versions: If you need to switch between different installed versions of Go, you can unlink the current version and link a different one:
shbrew unlink go@<current-version> brew link --force --overwrite go@<new-version>Replace
<current-version>and<new-version>with the appropriate version numbers.
By following these steps, you can easily manage and switch between different versions of Go on your system.
Step 3: Verify the Installation
After the installation is complete, verify that Go is installed correctly by running:
go versionYou should see the Go version information.
$ go version
> go version go1.21.3 darwin/arm64Additional Step: Setting up Go Environment
you can set GOPATH and GOROOT by adding the following lines to your ~/.bash_profile or ~/.zshrc
export GOPATH="$HOME/.go" # or any other directory you want
export GOROOT="$(brew --prefix golang)/libexec"
export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"References
| Source | Description |
|---|---|
| Go (opens in a new tab) | Go website |
| Go Documentation (opens in a new tab) | Go documentation |
| Go Tutorial (opens in a new tab) | Go tutorial |
| Setup your workspace (opens in a new tab) | The GOPATH and PATH environment variables |