How to Install Go 1.13.x on Ubuntu 18.04
Posted on In Linux, Programming, TutorialIn Ubuntu 18.04 LTS, the default Go lang version is 1.10. For compatibility reason, the Ubuntu LTS will usually keep the major release version numbers for packages. However, many applications, such as Hyperledger Fabric 2.0, require a newer version of Go. In this post, let’s take a look at how to install a system level Go of a higher version. Here, we use version 1.13.9 as an example.
An automatic installation script If you prefer to use a script to do this for you, you may run install-go.sh to replace step 2-4.
Table of Contents
Step 1. remove all go related packages in your system
It’s a good idea to remove all old go related packages in your system to avoid conflicts.
$ sudo apt remove 'golang-*'
Step 2. download the go lang release package
You can find the link from Go lang download page.
$ wget https://dl.google.com/go/go1.13.9.linux-amd64.tar.gz
You will see output as follows.
--2020-04-07 07:41:10-- https://dl.google.com/go/go1.13.9.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 216.58.197.110, 2404:6800:4005:80f::200e
Connecting to dl.google.com (dl.google.com)|216.58.197.110|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 120139686 (115M) [application/octet-stream]
Saving to: ‘go1.13.9.linux-amd64.tar.gz’
go1.13.9.linux-amd64.tar.gz 100%[================================================================>] 114.57M 1.28MB/s in 79s
2020-04-07 07:42:29 (1.45 MB/s) - ‘go1.13.9.linux-amd64.tar.gz’ saved [120139686/120139686]
Step 3. unpack the package to a local path
Unpack the downloaded package and move it to /usr/local/go-1.13
as the go root path. Here, we use a 1.13
suffix in the directory name so that later we may install multiple version of Go in the system if it is needed. Note, if the directory /usr/local/go-1.13
already exists, please remove it first.
$ tar xf go1.13.9.linux-amd64.tar.gz
$ sudo mv go /usr/local/go-1.13
Step 4. add script to set up environment
Add a file /etc/profile.d/Z99-go-1.13.sh
which contains following content.
export GOROOT=/usr/local/go-1.13
export PATH=$GOROOT/bin:$PATH
It sets the GOROOT
and PATH
environment variables for the Go we installed.
Now, log out and log in again so that new settings take effect for your login session.
Step 5. verify the new Go installation
Run a list of commands to verify whether Go works and the one invoked is the required version as follows.
Verify the command go
runs the correct executable binary file.
$ which go
/usr/local/go-1.13/bin/go
Verify the version is indeed the one we installed.
$ go version
go version go1.13.9 linux/amd64
Verify the GOROOT
environment variable is correct.
$ go env
...
GOROOT="/usr/local/go-1.13"
...
Now, everything good. Enjoy!
Super, helped me to install go1.13.9 separately thanks!
Nice, Very precise.