129

I tried the answer here Removed golang but go command still works?, but it didn't work (I can still run go)

Currently, when I run which go I see this output

/usr/local/go/bin/go

I think I had two installations of go as my GOPATH was pointing to another folder named gocode. I've now removed that folder, and the usr/local/go/bin/go folder.

I've also removed my GOPATH. However, I can still run go.

How do I uninstall go?

praks5432
  • 7,246
  • 32
  • 91
  • 156

15 Answers15

219

Update August 2019

Found the official uninstall docs worked as expected (on Mac OSX).

$ which go
/usr/local/go/bin/go

In summary, to uninstall:

$ sudo rm -rf /usr/local/go
$ sudo rm /etc/paths.d/go

Then, did a fresh install with homebrew using brew install go. Now, i have:

 $ which go
/usr/local/bin/go
Arnaud P
  • 12,022
  • 7
  • 56
  • 67
arcseldon
  • 35,523
  • 17
  • 121
  • 125
  • 24
    if you downvote, please can you leave a comment to clarify your reason. The above answer references and agrees with the official docs (Mac OSX). What didn't work for you? – arcseldon Aug 24 '19 at 13:28
  • Unfortunately that link doesn't go to uninstall docs anymore. – tom Dec 02 '20 at 19:05
  • 2
    I didnt DV but this would only work if you've installed to those paths which is only the Go packed install wizard thing. Installs via scripts, automation or choice can be anywhere. – Ben Racicot Feb 05 '21 at 01:42
  • 4
    Is there any advantage to use homebrew for installing Go, rather than the official *.pkg installer? – marcelosalloum Apr 21 '21 at 12:41
  • 4
    @tom I have fixed the link to official docs – Arnaud P Apr 21 '21 at 13:22
  • 1
    re: "*Is there any advantage to use homebrew for installing Go, rather than the official *.pkg installer?*" As with any package managers, using Homebrew just makes it convenient to update/upgrade and uninstall. No need to manually do these `rm` commands to uninstall Go. – Gino Mempin Sep 18 '22 at 07:25
92

You might try

rm -rvf /usr/local/go/

then remove any mention of go in e.g. your ~/.bashrc; then you need at least to logout and login.

However, be careful when doing that. You might break your system badly if something is wrong.

PS. I am assuming a Linux or POSIX system.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • 8
    I also recommend using https://github.com/moovweb/gvm it's made everything clean. – praks5432 Feb 12 '17 at 10:12
  • 6
    When installed via OsX graph.installer, remove also : sudo rm /etc/paths.d/go. (this removes old go-binary from PATH). – Esa Sep 18 '17 at 14:32
  • Don't forget `sudo ...` unless you're someone that likes to run everything as root... – DaveStephens Oct 10 '19 at 10:49
  • 1
    thanks, Basile it worked for me, but need to add "**sudo rm -rvf /usr/local/go/**" otherwise we get permission denial in mac os calalina – hemant singh Dec 11 '19 at 05:17
  • this doesn't work if in case you installed multiple go versions. so it's always better to run this sudo apt-get remove --auto-remove golang-go – Adarsha Jha Feb 03 '21 at 13:24
  • praks5432's comment above - using gvm - should be an answer, that's a fantastic tool and just saved me quite a bit of headache – therightstuff May 19 '21 at 08:22
  • use @praks5432's suggested `gvm`. It actually takes away a lot of the headache. – dodobird Jul 10 '21 at 04:54
79

I'm using Ubuntu. I spent a whole morning fixing this, tried all different solutions, when I type go version, it's still there, really annoying... Finally this worked for me, hope this will help!

sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go
loukaswho
  • 907
  • 6
  • 2
18

On a Mac-OS system

  1. If you have used an installer, you can uninstall golang by using the same installer.
  2. If you have installed from source
    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

On a Linux system

rm -rf /usr/local/go
rm -rf $(echo $GOPATH)

Then, remove all entries related to go i.e. GOROOT, GOPATH from ~/.bashrc and run

source ~/.bashrc
pratik singh
  • 213
  • 2
  • 4
  • "*you can uninstall golang by using the same installer.*" No you can't. Re-running the same installer will just do a fresh re-installation. There was no "uninstall" option. – Gino Mempin Sep 18 '22 at 07:23
13

Update (Sep, 2022)

The official page has changed path for the uninstallation help along with the help text. Here is what it says now.

Uninstalling Go

You can remove Go from your system using the steps described in this topic.

Linux / macOS / FreeBSD

  1. Delete the go directory.
    This is usually /usr/local/go.

  2. Remove the Go bin directory from your PATH environment variable.
    Under Linux and FreeBSD, edit /etc/profile or $HOME/.profile. If you installed Go with the macOS package, remove the /etc/paths.d/go file.

Windows

The simplest way to remove Go is via Add/Remove Programs in the Windows control panel:

  1. In Control Panel, double-click Add/Remove Programs.
  2. In Add/Remove Programs, select Go Programming Language, click Uninstall, then follow the prompts.

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
    Note: Using this uninstall process for Windows will automatically remove Windows environment variables created by the original installation.

Original Answer

From the official install page -

To remove an existing Go installation from your system delete the go directory. This is usually /usr/local/go under Linux, macOS, and FreeBSD or c:\Go under Windows.

You should also remove the Go bin directory from your PATH environment variable. Under Linux and FreeBSD you should edit /etc/profile or $HOME/.profile. If you installed Go with the macOS package then you should remove the /etc/paths.d/go file. Windows users should read the section about setting environment variables under Windows.

0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
  • 2
    @zixuan The quoted text explains it very well. Nobody mentioned the official docs, so I did. Do you find it ambiguous? – 0xC0DED00D Aug 07 '19 at 22:22
12

For Windows 10:

  1. Go to Apps in the Settings App.
  2. Look for Go Programming Language * in the list and uninstall it.
  3. Remove C:\Go\bin from your PATH environment variable (only if you don't plan on installing another version of golang)
Jaco Briers
  • 1,703
  • 1
  • 21
  • 34
6

Use this command to uninstall Golang for Ubuntu.

This will remove just the golang-go package itself.

sudo apt-get remove golang-go

Uninstall golang-go and its dependencies:

sudo apt-get remove --auto-remove golang-go
Adrian W
  • 4,563
  • 11
  • 38
  • 52
Anshu
  • 1,277
  • 2
  • 13
  • 28
  • @adrian W can you please explain what is my mistakes. – Anshu May 28 '19 at 07:26
  • Nobody said it is a mistake. Just reformatted to suit the style which is usual in SO posts. I.e. text which is literal computer in/output (such as a shell command) is formatted as code block. It was formatted as citation before. – Adrian W May 28 '19 at 13:28
4

I just have to answer here after reading such super-basic advice in the other answers.

For MacOS the default paths are:

  1. /user/bracicot/go (working dir)
  2. /usr/local/go (install dir)

When uninstalling remove both directories.
If you've installed manually obviously these directories may be in other places.

One script I came across installed to /usr/local/.go/ a hidden folder because of permissioning... this could trip you up.

In terminal check:

echo $GOPATH
echo $GOROOT
#and
go version

For me after deleting all go folders I was still getting a go version.

Digging through my system path echo $PATH

/Users/bracicot/google-cloud-sdk/bin:/usr/local/bin:

revealed some places to check for still-existing go files such as /usr/local/bin

Another user mentioned: /etc/paths.d/go

You may also want to remove GOPATH and GOROOT environment variables.
Check .zshsrc and or .bash_profile.
Or you can unset GOPATH and unset GOROOT

Ben Racicot
  • 5,332
  • 12
  • 66
  • 130
2

To uninstall go on MacOS, do this: On the terminal type which go it will; return a path like this /usr/local/go/bin/go Go to the root folder of go which is /usr/local/go/ and type on the terminal rm -rf /usr/local/go/ . you may get permission denied depending on your system setup, so the command should be prefixed with sudo like this

sudo rm -rf /usr/local/go/

It will request for your password, just enter it.

ken4ward
  • 2,246
  • 5
  • 49
  • 89
1
sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go

This is perfect for Ubuntu 18.18

gil
  • 1,318
  • 12
  • 19
abrid
  • 37
  • 1
1

On a Mac-OS Catalina

  1. need to add sudo before rm -rf /usr/local/go sudo rm -rf /usr/local/go otherwise, we will run into permission denial.

  2. sudo vim ~/.profile or sudo ~/.bash_profile remove export PATH=$PATH:$GOPATH/BIN or anything related to go lang

  3. If you use Zsh shell, then you need to remove the above line to ~/.zshrc file.

Hope it helps you :)

hemant singh
  • 149
  • 3
  • 7
0

In MacOS, you can just do it with brew:

brew uninstall go
brew install go
brew upgrade go
double-beep
  • 5,031
  • 17
  • 33
  • 41
timtike
  • 41
  • 1
-1

On linux we can do like this to remove go completely:

rm -rf "/usr/local/.go/"
rm -rf "/usr/local/go/"

These two command remove go and hidden .go files. Now we also have to update entries in shell profile.

Open your basic file. Mostly I open like this sudo gedit ~/.bashrc and remove all go mentions.

You can also do by sed command in ubuntu

sed -i '/# GoLang/d' .bashrc
sed -i '/export GOROOT/d' .bashrc
sed -i '/:$GOROOT/d' .bashrc
sed -i '/export GOPATH/d' .bashrc
sed -i '/:$GOPATH/d' .bashrc

It will remove Golang from everywhere. Also run this after running these command

source ~/.bash_profile

Tested on linux 18.04 also. That's All.

amku91
  • 1,010
  • 11
  • 21
-3
  1. Go to the directory

    cd /usr/local
    
  2. Remove it with super user privileges

    sudo rm -rf go
    
Pang
  • 9,564
  • 146
  • 81
  • 122
harold ramos
  • 639
  • 7
  • 6
-3

only tab
rm -rvf /usr/local/go/
not works well, but
sudo rm -rvf /usr/local/go/
do.

Yan Li
  • 5
  • 2