Building Go from source on Linux (Ubuntu 18.04)
This is the way I’ve built/set up Go from source on a brand new system (that didn’t have Go installed previously) following the official docs.
-
Create an empty
$HOME/go
directory -
Download and extract the go1.4 source distribution to
$HOME
, and rename the directory you just unpacked togo1.4
. -
To build the bootstrap toolchain run the following:
$ cd $HOME/go1.4
$ ./make.bash
(setting CGO_ENABLED=0 was not necessary for me)
- Fetch the Go repository and install the desired version:
$ cd /usr/local/
$ git clone https://go.googlesource.com/go
To install and change between versions, checkout the stable version’s branch e.g git checkout go1.10.3
or stay in master
for the development branch, and run:
$ cd /usr/local/go/src/
$ ./all.bash
It will take some time to build and run all the tests, once this is done add the following to your ~/.profile
, ~/.bash_profile
or whichever file you use to be executed when you start a shell.
export GOROOT=/usr/local/go
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:/home/[YOUR USER]/go/bin
apply the changes:
$ source ~/.profile
- Verify the version installed
$ go version
go version devel +f17220c208 Tue Jul 17 05:41:06 2018 +0000 linux/amd64
VGO / Go Modules
If you have the master
branch installed these will be available by default since CL 123580. For more information on usage run go help modules
on your CLI