How to install the current version of Go in Ubuntu Precise

UbuntuGo

Ubuntu Problem Overview


Running sudo apt-get install golang-stable, I get Go version go1.0.3. Is there any way to install go1.1.1?

Ubuntu Solutions


Solution 1 - 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

Solution 2 - Ubuntu

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.

Solution 3 - Ubuntu

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.

Solution 4 - Ubuntu

[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: https://stackoverflow.com/questions/29514456/go-is-printing-xgcc-version-but-not-go-installed-version

Solution 5 - Ubuntu

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

Solution 6 - Ubuntu

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.

Solution 7 - Ubuntu

I use this instruction to install the latest version of https://i.stack.imgur.com/R27Lx.png" width="24" height="32" alt="IMG: " title="golang">

  1. Remove the existing Go version:

    sudo apt-get purge golang*
    
  2. Install the latest version of Go:

    sudo add-apt-repository ppa:longsleep/golang-backports
    sudo apt-get update
    sudo apt-get install golang-go
    
  3. Create the .profile file in the home path with this content:

    # ~/.profile: executed by the command interpreter for login shells.
    # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
    # exists.
    # see /usr/share/doc/bash/examples/startup-files for examples.
    # the files are located in the bash-doc package.
    
    # the default umask is set in /etc/profile; for setting the umask
    # for ssh logins, install and configure the libpam-umask package.
    #umask 022
    
    # if running bash
    if [ -n "$BASH_VERSION" ]; then
        # include .bashrc if it exists
        if [ -f "$HOME/.bashrc" ]; then
            . "$HOME/.bashrc"
        fi
    fi
    
    # set PATH so it includes user's private bin directories
    PATH="$HOME/bin:$HOME/.local/bin:$PATH"
    
  4. Set Go workspace to the environment variable:

    GOPATH=~/.go
    
  5. Apply the .profile configuration:

    source ~/.profile
    

Test:

$ go version
go version go1.11.1 linux/amd64

Ref: Go-GitHub-Installation

Solution 8 - Ubuntu

For the current release of Go:

> The Go Programming Language > > Getting Started > > Download the Go distribution > > Downloads > > > Click the link above to visit the Go project's downloads page and > select the binary distribution that matches your operating system and > processor architecture. > > Official binary distributions are available for the FreeBSD, > Linux, macOS, and Windows > operating systems and the 32-bit (386) and 64-bit (amd64) x86 > processor architectures. > > If a binary distribution is not available for your combination of > operating system and architecture you may want to try installing from > source or installing gccgo instead of gc. > > > Installing Go from source

Solution 9 - Ubuntu

If someone is looking for installing Go 1.8 the follow this:

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

And then install go

sudo apt-get install golang-1.8-go

Solution 10 - Ubuntu

> 1. Download say, go1.6beta1.linux-amd64.tar.gz from https://golang.org/dl/ into /tmp

wget https://storage.googleapis.com/golang/go1.6beta1.linux-amd64.tar.gz -o /tmp/go1.6beta1.linux-amd64.tar.gz

> 2. un-tar into /usr/local/bin

sudo tar -zxvf go1.6beta1.linux-amd64.tar.gz -C /usr/local/bin/

> 3. Set GOROOT, GOPATH, [on ubuntu add following to ~/.bashrc]

mkdir ~/go export GOPATH=~/go export PATH=$PATH:$GOPATH/bin export GOROOT=/usr/local/bin/go export PATH=$PATH:$GOROOT/bin

>4. Verify

go version should show be

>go version go1.6beta1 linux/amd64

go env should show be

>GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/vats/go" GORACE="" GOROOT="/usr/local/bin/go" GOTOOLDIR="/usr/local/bin/go/pkg/tool/linux_amd64" GO15VENDOREXPERIMENT="1" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0" CXX="g++" CGO_ENABLED="1"

Solution 11 - Ubuntu

These days according to the golang github with for Ubuntu, it's possible to install the latest version of Go easily via a snap:

> Using snaps also works quite well:

# This will give you the latest version of go
$ sudo snap install --classic go

Potentially preferable to fussing with outdated and/or 3rd party PPAs

Solution 12 - Ubuntu

On recent Ubuntu (20.10) sudo apt-get install golang works fine; it will install version 1.14.

Solution 13 - Ubuntu

Or maybe you could use this script to install Go and LiteIDE?

If you are unhappy with the answer provided, please comment instead of blindly down voting. I have used this setup for the last 4 years without any issue.

Solution 14 - Ubuntu

You can also use the update-golang script:

update-golang is a script to easily fetch and install new Golang releases with minimum system intrusion

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh

Solution 15 - Ubuntu

  1. If you have ubuntu-mate, you can install latest go by:

    umake go

  2. I have a script to download and install the last go from official website

      # Change these varialbe to where ever you feel comfortable
      DOWNLOAD_DIR=${HOME}/Downloads/GoLang
      INSTALL_DIR=${HOME}/App
      function install {
         mkdir -p ${DOWNLOAD_DIR}
         cd ${DOWNLOAD_DIR}
    
         echo "Fetching latest Go version..."
         typeset VER=`curl -s https://golang.org/dl/ | grep -m 1 -o 'go\([0-9]\)\+\(\.[0-9]\)\+'`
         if uname -m | grep 64 > /dev/null; then
             typeset ARCH=amd64
         else
             typeset ARCH=386
         fi
         typeset FILE=$VER.linux-$ARCH
    
         if [[ ! -e ${FILE}.tar.gz ]]; then
              echo "Downloading '$FILE' ..."
              wget https://storage.googleapis.com/golang/${FILE}.tar.gz
         fi
    
         echo "Installing ${FILE} ..."
         tar zxfC ${FILE}.tar.gz ${INSTALL_DIR}
         echo "Go is installed"
     }
    
     install
    

Setup your GOROOT, GOPATH and PATH:

export GOROOT=${INSTALL_DIR}/go
export GOPATH=<your go path>
export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin

Solution 16 - Ubuntu

You can use a script from udhos/update-golang.

Here is a two-liner as example (run as root):

bash <(curl -s https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh)
ln -vs /usr/local/go/bin/go* /usr/local/bin/

Solution 17 - Ubuntu

Best way to install Go on Ubuntu is to download required version from here. Here you could have all stable and releases, along with archived versions.

after downloading you selected version you can follow further steps, i will suggest you to download tar.gz format for ubuntu machine:

  1. first of all fully remove the older version from your local by doing this

sudo rm -rf /usr/local/go /usr/local/gocache

this will remove all the local go code base but wait something more we have to do to remove fully from local, i was missing this step and it took so much time until I understood what i am missing so here is the purge stuff to remove from list

> sudo apt-get purge golang

or

> sudo apt remove golang-go

  1. Now install / extract your downloaded version of go inside /usr/local/go, by hitting terminal with this

> tar -C /usr/local -xzf go1.10.8.linux-amd64.tar.gz

  1. after doing all above stuff , don't forget or check to GOROOT variable value you can check the value by go env if not set then export PATH=$PATH:/usr/local/go
  2. Better to test a small go program to make sure. write this inside /home/yourusername/go/test.php if you haven't changed set GOPATH value:

> package main >
> import "fmt" >
> func main() { > fmt.Println("hello world") > }

  1. run this by go run test.go

i hope it works for you!!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsccView Question on Stackoverflow
Solution 1 - UbuntusccView Answer on Stackoverflow
Solution 2 - UbuntunojView Answer on Stackoverflow
Solution 3 - UbuntuPankaj KhairnarView Answer on Stackoverflow
Solution 4 - Ubuntukemicofa ghostView Answer on Stackoverflow
Solution 5 - UbuntumnagelView Answer on Stackoverflow
Solution 6 - UbuntuIshan JainView Answer on Stackoverflow
Solution 7 - UbuntuBenyamin JafariView Answer on Stackoverflow
Solution 8 - UbuntupeterSOView Answer on Stackoverflow
Solution 9 - UbunturakibtgView Answer on Stackoverflow
Solution 10 - UbuntusuryakrupaView Answer on Stackoverflow
Solution 11 - UbuntukjonesView Answer on Stackoverflow
Solution 12 - Ubuntuuser2023370View Answer on Stackoverflow
Solution 13 - UbuntuthorocView Answer on Stackoverflow
Solution 14 - UbuntuEvertonView Answer on Stackoverflow
Solution 15 - UbuntuEnze ChiView Answer on Stackoverflow
Solution 16 - UbuntukenorbView Answer on Stackoverflow
Solution 17 - UbuntuAshutosh RaiView Answer on Stackoverflow