go
Step-by-step guide to install Go on macOS:
- Open a web browser and go to the official Go download page at https://golang.org/dl/.
Once the download is complete, open the package by double-clicking on the file. This will launch the Go installer.
- In the Terminal window, type the following command to verify that Go is installed and working properly:
$ go version
go version go1.20.1 darwin/amd64
Tip
You can open the Terminal app on your Mac by pressingCommand+Space
to open Spotlight Search, type Terminal
and then press Enter
.- Next, you will need to set your Go workspace. The workspace is the directory where your Go projects and packages will be stored. To set your workspace, create a new directory in your home directory by running the following command:
mkdir ~/go
After creating the directory, you’ll need to set the GOPATH
environment variable to point to your workspace directory. To do this, add the following line to your ~/.zshrc
file:
export GOPATH=$HOME/go
You can do this by opening the file in a text editor using the following command:
nano ~/.zshrc
Then add the above line to the end of the file and save it by pressing Ctrl+X, then Y, then Enter.
- Finally, restart the Terminal app to apply the changes to the GOPATH environment variable.
Uninstall go
- Check in Terminal if go was installed with package
$ pkgutil --pkgs | grep golang
org.golang.go
- Check where files are istalled
$ pkgutil --files org.golang.go | more
etc
etc/paths.d
etc/paths.d/go
usr
usr/local
usr/local/go
usr/local/go/CONTRIBUTING.md
usr/local/go/LICENSE
...
- Remove folder recursively
$ rm -r /usr/local/go
- Remove the system record of the go package.
$ sudo pkgutil --forget org.golang.go.pkg