Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install the current version of Go in Ubuntu Precise

Tags:

go

ubuntu

[Updated (previous answer no longer applied)]

For fetching the latest version:

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go

Also see the wiki


I like to use GVM for managing my Go versions in my Ubuntu box. Pretty simple to use, and if you're familiar with RVM, it's a nobrainer. It allows you to have multiple versions of Go installed in your system and switch between whichever version you want at any point in time.

Install GVM with:

sudo apt-get install bison mercurial
bash < <(curl -LSs 'https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer')
. "$HOME/.gvm/scripts/gvm"

and then it's as easy as doing this:

gvm install go1.1.1
gvm use go1.1.1 --default

The default flag at the end of the second command will set go1.1.1 to be your default Go version whenever you start a new terminal session.


I used following commands from GoLang official repository, it installed GoLang version 1.6 on my Ubuntu 14.04

sudo add-apt-repository ppa:ubuntu-lxc/lxd-stable
sudo apt-get update
sudo apt-get install golang

Reference official GoLang Repo https://github.com/golang/go/wiki/Ubuntu it seems this ppa will always be updated in future.


[October 2015] Answer because the current accepted answersudo apt-get install golang isn't uptodate and if you don't want to install GVM follow these steps.

Step by step installation:

  1. Download the latest version here (OS: Linux).
  2. Open your terminal and go to your Downloads directory
  3. sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
  4. Add go to your path export PATH=$PATH:/usr/local/go/bin
  5. go version to check the current version installed
  6. Start programming.

Possible errors + fixes: (to be updated)

If you get a go version xgcc (Ubuntu 4.9.1-0ubuntu1) 4.9.1 linux/amd64 then you did something wrong, so check out this post: Go is printing xgcc version but not go installed version


i installed from source. there is a step-by-step tutorial here: http://golang.org/doc/install/source


Here is the most straight forward and simple method I found to install go on Ubuntu 14.04 without any ppa or any other tool.

As of now, The version of GO is 1.7

Get the Go 1.7.tar.gz using wget

wget https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz

Extract it and copy it to /usr/local/

sudo tar -C /usr/local -xzvf go1.7.linux-amd64.tar.gz

You have now successfully installed GO. Now You have to set Environment Variables so you can use the go command from anywhere.

To achieve this we need to add a line to .bashrc So,

sudo nano ~/.bashrc

and add the following line to the end of file.

export PATH="/usr/local/go/bin:$PATH"

Now, All the commands in go/bin will work.

Check if the install was successful by doing

go version

For offline Documentation you can do

godoc -http=:6060

Offline documentation will be available at http://localhost:6060

NOTE:

Some people here are suggesting to change the PATH variable.

It is not a good choice.

  1. Changing that to /usr/local/go/bin is temporary and it'll reset once you close terminal.

  2. go command will only work in terminal in which you changed the value of PATH.

  3. You'll not be able to use any other command like ls, nano or just about everything because everything else is in /usr/bin or in other locations. All those things will stop working and it'll start giving you error.

However, this is permanent and does not disturbs anything else.