In this tutorial we will cover different methods to properly uninstall go from multiple distributions such as Linux, Windows, Mac etc.
Uninstall Golang on Linux
Method 1: Remove the go directory
This method has to be used if you are using go from an archive which was download from official repository. Run the following command on your terminal to identify the location of the Go binary, and copy the output to your clipboard:
which go
Run the rm
command to remove the Go binary after copying its path. You might also need to run sudo:
sudo rm -rvf /usr/local/go/
Your .bash
profile or .bashrc
file may contain export definitions for $GOPATH
or $PATH (Â If you installed Go with the macOS package, remove the /etc/paths.d/go file). The final step is to remove these environment variables.
Method 2: Using apt-get package manager
The apt-get command can be used on Debian based distributions such as Ubuntu. To uninstall golang-go
package itself from Ubuntu executes on the terminal:
sudo apt-get remove golang-go
To remove the golang-go
package from Ubuntu as well as any other dependent packages that are no longer required:
sudo apt-get autoremove golang-go
This will work if you also want to remove the golang-go
configuration and/or data files from Ubuntu:
sudo apt-get purge golang-go
Execute the following command to remove the golang-go
and its dependencies from Ubuntu's configuration and/or data files:
sudo apt-get autoremove --purge golang-go
Method-3: Using yum or dnf package manager
On Red Hat based Linux distributions we must use yum or dnf package manager. So uninstall golang package from Red Hat based distributions such as CentOS, Rocky Linux, AlmaLinux you can first check whether golang package is installed
# rpm -qa | grep golang
If available then you can remove them using
# yum -y remove golang golang-src golang-bin
Uninstall Golang on Windows
Go can be easily uninstalled using Add/Remove Programs in the Windows control panel:
1. Go to the Control Panel section, and double-click Add/Remove Programs.
2. In Add/Remove Programs, right-click the go version you want to uninstall (for example Go Programming Language amd64 go1.19.3) then follow the prompts.
3. Click Yes to confirm uninstall Go
For removing Go with tools, you can also use the command line:
Uninstall using the command line by running the following command:
msiexec /x go{{version}}.windows-{{cpu-arch}}.msi /q
It should be noted that this method of uninstalling Windows will immediately delete any environment variables set up during the initial installation.
Uninstall Golang on MacOS
If you have used an installer, you can uninstall golang by using the same installer.
If you have installed from source then rm -rf /usr/local/go
rm -rf $(echo $GOPATH)
Then, remove all entries related to go i.e. GOROOT, GOPATH from ~/.bash_profile
 and run
source ~/.bash_profile
If you installed Go with the macOS package, remove the /etc/paths.d/go
file.
Summary
After reading this article, you should understand how to remove Go from your personal computers. In the case of upgrading the Go version, we can delete the older and install a newer version or even set up multiple versions in 1 environment. The Go method for running multiple Go versions is straightforward and elegant because it makes use of standard Go features.
References