Skip to content

Instantly share code, notes, and snippets.

@fscm
Last active June 21, 2021 18:57
Show Gist options
  • Save fscm/67dc82758ed498c6ad9a1444955a4c74 to your computer and use it in GitHub Desktop.
Save fscm/67dc82758ed498c6ad9a1444955a4c74 to your computer and use it in GitHub Desktop.
[macOS] Install Go programming language

[macOS] Install Go programming language

Instructions on how to install the Go programming language on macOS.

Uninstall

First step should be to unsinstall any previous Go installation. This step can be skipped if no Go version was previously installed.

To uninstall any previous Go installations use the following commands:

sudo rm -rf /usr/local/go

Install

The Go programming language can be obtained here. Copy the link for the archive version that you want to install from there.

Get the Go programming language archive and extract it with the following command:

sudo mkdir -p /usr/local/go
curl --silent --location --retry 3 "https://golang.org/dl/go1.16.5.darwin-amd64.tar.gz" | sudo tar xz --no-same-owner --strip-components=1 -C /usr/local/go

Configure

Go tools expect a certain layout of the source code. To create the required folders use the following commands:

mkdir -p ${HOME}/Documents/Projects/Go/{bin,pkg,src}

To make go use those folders the following lines will have to be added to the .bash_profile file:

export GOROOT="/usr/local/go"
export GOPATH="${HOME}/Documents/Projects/Go"
export GOBIN="${GOPATH}/bin"
export PATH="${PATH}:${GOROOT}/bin:${GOBIN}"

Write your code inside the ${HOME}/Documents/Projects/Go/src folder.

Verify

Open a new terminal window and check if the Go programming language is installed:

go version
go env

Also check the value of the environment variables - on the output of the go env command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment