21

I'm trying to install drive, which requires Go.

I did:

sudo apt-get install golang git mercurial

which successfully installed version 1.2.1. Unfortunately, when I tried to install drive with:

go get -u github.com/odeke-em/drive/cmd/drive

I encountered this error, and now I see I need at least version 1.4 of Go to make things work. The golang doc says you must first remove the existing version.

So I came across this question that says to simply use:

sudo apt-get purge golang

which gave me this output:

The following packages will be REMOVED:
golang*
0 upgraded, 0 newly installed, 1 to remove and 16 not upgraded.
After this operation, 92.2 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 263287 files and directories currently installed.)
Removing golang (2:1.2.1-2ubuntu1) ...

(no more output after the three dots—just back to the prompt).

But I still see the go directory in /usr/lib/, and there's also still a gopath directory in my home directory.

which I think was created when I did:

$ cat << ! >> ~/.bashrc
> export GOPATH=\$HOME/gopath
> export PATH=\$GOPATH:\$GOPATH/bin:\$PATH
> !
$ source ~/.bashrc # To reload the settings and get the newly set ones # Or open a fresh terminal

during the installation (to create the GOPATH).

So I'm not sure if the uninstall was successful and if it's safe to install a newer version of Go.

Ubuntu 14.04 LTS

yroc
  • 318
  • 2
    To downvoter: Are you kidding me? – yroc Mar 04 '16 at 15:34
  • You get my upvote for the downvoter. Stop that drive-by downvote crap. This is a seriously annoying problem, I was glad to find the question, thanks. – moodboom Jul 19 '21 at 14:40

5 Answers5

39

I spent a whole morning fixing this, tried all different solutions, when I type go version, it's still there, really annoying...

This worked for me.

sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go

Check this original post :D

M.A.K. Ripon
  • 3,139
loukaswho
  • 491
  • 1
    --auto-remove force it to remove all from linux-images which consumed around 10 minutes. @loukaswho – alper Aug 27 '18 at 13:40
14

I realize that this is a little old, but the answers at https://golang.org/doc/manage-install#uninstalling may help you.

Essentially just removing the directories /usr/local/go or /usr/lib/go and modifying your path at /etc/profile or $HOME/.profile should be enough.

perfect5th
  • 241
  • 2
  • 5
3

best way to uninstall is to open terminal and type

sudo apt-get uninstall purge golang*

this removes every package associated with go. Then you can run

sudo apt-get update

But if you did that and nothing worked, you can do this

sudo rm -rf /usr/local/go

then try running the purge again. But You should update to Go 1.8, which sets the GOPATH for you. But hey! before updating first remove existing golang.

connelblaze
  • 2,129
3

First you have to remove all the go-packages in your system by type this code from terminal

sudo apt-get purge golang*

Then follow the instructions to download and install golang

Official golang website

Ravexina
  • 55,668
  • 25
  • 164
  • 183
1

As mentioned in official docs

  1. Firstly, delete the go directory. Mostly it will be /usr/local/go. If you are not sure check it using which go. So, run sudo rm -rf /usr/local/go.

  2. Next you need to remove the Go bin directory from your PATH environment variable. i.e. remove GOBIN, GOPATH from ~/.bashrc.