Uninstall Go on macOS
Check if Go is installed
Let’s start with checking if Go actually installed on machine.
To see version of Go run this command:
go version
To see Go location run this one:
which go
Default value is /usr/local/bin/go.
Go installation options
There are multiple ways to setup Go dev environment. Developer can pick an option that provides more flexibility or more simplicity. Flexibility is presented by packaged Go binaries .darwin-amd64.tar.gz archive when simplicity is achieved with package management tools like Homebrew. An option in between is .darwin-amd64.pkg macOS package installer
What is important to understand is that you can have several versions of Go installed on machine using several different methods. In that case, there is no single solution to uninstall all these versions and multiple places need to be checked.
If Go installed using Homebrew
Homebrew is a smart package manager that is capable of cleaning up after itself.
It is recommended to use built-in uninstall command if Go was installed using brew.
Command below uninstalls Dep and Go if it was installed using brew:
brew uninstall dep
brew uninstall go
Homebrew cleans up $PATH and other config files. No extra steps are necessary if Go was never installed using different options.
tip:
brewkeeps Go files in/usr/local/Cellar/go/x.x.x/folder
If Go installed using macOS package
Run the command line to see if Go was installed using macOS package
pkgutil --pkgs
Go macOS package is presented as com.googlecode.go in result list.
macOS package stores files in the predefined location. For Go version 1.12 these are the files to be deleted:
- file /etc/paths.d/go
- folder usr/local/go
There is a command line to check if files are moved to different location in future Go versions:
pkgutil --only-files --files com.googlecode.go
Next step is to remove the system record of Go package:
sudo pkgutil --forget com.googlecode.go
Cleaning up $PATH environment variable to be performed manually as described below.
Removing files manually
- /etc/paths.d/gocheck if that file exists and remove. It is added by macOS package.
- /usr/local/gocheck if that folder exists and remove. macOS package keeps Go files in that folder.
- Check $PATHfor*/go/bin. That is a good hint find where Go is installed. Delete thatgofolder.
- $HOME/goor- $GOPATH- Go Workspace. Important! This folder may contain not pushed code in- /srcsub-folder. Be careful to not lost your work.
Environment Variables
- $PATHcontains path to Go binaries (- /usr/local/go/binby default). Update- $PATHto exclude path to Go binaries.
- $GOPATHmay contain override for workspace path default value- $HOME/go. Remove- $GOPATHif it exists.
Happy uninstalling!