I have Ubuntu 14.4.03. The default golang version which came with it was 1.2.1. I would like to update golang to 1.4 or higher.
After searching I found the way to do this would be to first delete current go installation and then re-install the new version.
I found the following go installation files in the following directory:
/usr/share/go
/usr/share/go/src/cmd/go
/usr/share/go/src/pkg/go
/usr/lib/go
/ur/lib/go/pkg/linux_amd64/go
/ur/lib/go/pkg/linux_amd64_race/go
/usr/bin/goWhich directory contains what? Which ones should I delete? What should be the location of new installation? It seems /usr/local is more normal. Then how come Ubuntu default is as above?
What would be the procedure to install a new version og golang?
Thanks.
111 Answers
ppa:evarlast/golang1.4 is not working for me. The manual way of installing Go is given below.
For more detailed installation instruction: Install the latest Golang on Linux
Step 1: Remove the existing golang
sudo apt-get purge golang*Step 2: Download the latest version from the official site. Click Here
Step 3: Extract it in /usr/local using the following command. I am using Go 1.11.4 here. You may need to replace the filename with the actual filename based on the version you have downloaded.
tar -C /usr/local -xzf go1.11.4.linux-amd64.tar.gzStep 4: Create .go directory in home. (It is easy to install the necessary packages without admin privilege)
mkdir ~/.goStep 5: Set up the following environment variables
GOROOT=/usr/local/go
GOPATH=~/.go
PATH=$PATH:$GOROOT/bin:$GOPATH/binCheck this link on how to set environment variables permanently.
Step 6: Update the go command
sudo update-alternatives --install "/usr/bin/go" "go" "/usr/local/go/bin/go" 0
sudo update-alternatives --set go /usr/local/go/bin/goStep 7: Test the golang version
go version 6 First remove your current golang installation with this command, you don't need to manually remove files installed by apt-get,
sudo apt-get purge golangFor an easy install of golang 1.4 you can use this PPA
sudo add-apt-repository ppa:evarlast/golang1.4
sudo apt-get updateNow you can use
sudo apt-get install golangThis will install version 1.4, here is a link to the PPA.
1I have found an alternative(/personal) repo with latest versions, which is still alive, then got the go-1.8 and linked it from the path in the OP's question. Here be bash it in:
sudo add-apt-repository ppa:gophers/archive
sudo apt-get update
sudo apt-get install golang-1.8
sudo ln /usr/lib/go-1.8/bin/go /usr/bin/go1.8Now I can just say go1.8 instead of go and thus go with the latest&greatest.
The repo offers many other versions so you'd just change the version number to ex. 1.4 in the script/commands above.
For Golang 1.8 on Ubuntu 17.04 Zesty to 17.10 Artful:
# sudo apt update
# sudo apt install golang-1.8 golang-1.8-doc
# for bin in /usr/lib/go-1.8/bin/* ; do sudo update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 0 sudo update-alternatives --set $(basename $bin) $bin doneFor Golang 1.9 on Ubuntu 17.10 Artful to 18.04 Bionic:
# sudo apt update
# sudo apt install golang-1.9 golang-1.9-doc
# for bin in /usr/lib/go-1.9/bin/* ; do sudo update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 0 sudo update-alternatives --set $(basename $bin) $bin doneFor Golang 1.10 on Ubuntu 18.04 Bionic and 18.10 Cosmic:
# sudo apt update
# sudo apt install golang-1.10 golang-1.10-doc
# for bin in /usr/lib/go-1.10/bin/* ; do sudo update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 0 sudo update-alternatives --set $(basename $bin) $bin done To install the latest version of Go programming language in all currently supported versions of Ubuntu open the terminal and type:
sudo snap install go --classic --channel stable You might need to install snapd support because this is not installed by default on server installations.
sudo apt install snapd && sudo rebootThis snap provides an assembler, compiler, linker, and compiled libraries for the Go programming language. There are other channels besides stable, but the stable channel is the latest version of Go programming language. The go snap package will be updated automatically when updates are available.
Easy install and update
# Add basic packages
sudo apt-get install curl git mercurial make binutils bison gcc build-essential
# Install GVM
bash < <(curl -s -S -L )
# Install which version you want to install
gvm install go1.9
# Use it as default version
gvm use go1.9 --default 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
cd update-golang
sudo ./update-golang.sh I use this script to automate Golang updates:
2Remove existing golang
sudo apt-get purge golang*Install snap if not yet installed
sudo apt update
sudo apt install snapdInstall via snap
sudo snap install go --classic Learn latest version from:
sudo apt-get purge golang* # in case there is old version of go is installed
tar_name="go1.15.8.linux-amd64.tar.gz" # get latest version from
wget
tar -xvf $tar_name
rm -f $tar_name
sudo rm -rf /usr/local/go
sudo mv go /usr/local
# Add following lines into `.bashrc` or `.zshrc`
mkdir -p $HOME/go
export GOPATH=$HOME/go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin I use this instruction to install the latest version of ![golang IMG:]()
Remove the existing Go version:
sudo apt-get purge golang*Install the latest version of Go:
sudo add-apt-repository ppa:longsleep/golang-backports sudo apt-get update sudo apt-get install golang-goCreate the
.profilefile 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"Set Go workspace to the environment variable:
GOPATH=~/.goApply the
.profileconfiguration:source ~/.profile
Test:
$ go version
go version go1.11.1 linux/amd64