Want to learn how to build better Go applications faster and easier? You can.
Check out my course on the Go Standard Library. You can check it out now for free.
If you want to install Go on a Mac, it’s easy.
Download the latest stable release of Go from the official website.
Extract the downloaded tarball using the following command:
tar -xvf go1.x.x.darwin-amd64.tar.gz
Replace x.x with the actual version number of Go.
sudo mv go /usr/local
export PATH=$PATH:/usr/local/go/bin
source ~/.bash_profile
go version
This should print the installed version of Go.
You may also want to set up your Go workspace by defining the GOPATH environment variable. The GOPATH variable specifies the location of your Go workspace, where your Go source code and libraries are stored. By default, the go command will look for packages in the $GOPATH/src directory and will store the compiled binaries in the $GOPATH/bin directory.
To set the GOPATH variable, open the ~/.bash_profile file and add the following line:
export GOPATH=$HOME/go
Replace $HOME/go with the desired location of your Go workspace.
Don’t forget to reload your ~/.bash_profile file to apply the changes:
source ~/.bash_profile
That’s it! You now have Go installed on your Mac.