Learn Go in One Night: Installation on Linux/WSL (Windows Subsystem)
Download :
First of all download golang. Check the newest stable here.
Find your OS. In my case the 64 bits Linux linux-amd64
, use the same package for Linux on Windows WSL.
Getting Started
Download with wget
command and extract it with tar
and remove the zipped download.
$ wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
$ tar xzvf go1.14.4.src.tar.gz
$ rm go1.14.4.linux-amd64.tar.gz
Then we will make it callable by copy it to the system path /usr/local/lib
. We link the go
command to the system binary path /usr/local/bin
.
sudo mv go/ /usr/local/lib/
sudo ln -s /usr/local/lib/go/bin/go /usr/local/bin/go
Warning: ln
must specific absolute path otherwise it will be double relative and throw this error Too many levels of symbolic links
Add GOROOT and GOPATH
GOROOT
is the folder we download and there contains standard module hereGOPATH
is your working directory just it’s the home directory for go in your machine
Add these two lines into your .bash_profile
to make it permanent.
export GOPATH="$HOME/go/" export GOROOT="/usr/local/lib/go"
Testing
We test call the go
from the CLI here and check if the environment is set.
$ go version
$ go env
Some Notes
Note: The word amd64
is not actually an AMD it is just 64 bits arch that AMD invented. If you are on computer not embedded system, it is likely to be 64 bit.
Note: The file https://dl.google.com/go/go1.14.4.src.tar.gz
is the source code. When compile on each system (Mac, Window, Linux) it will have an output to be each one provided on the links.
Note: Why might you need to do this on Linux is because Debian/Ubuntu released Go is below 1.10 and Go doesn’t have the Go Module support before 1.10 so you need this. To remove the previous version of Go you can do:
$ sudo apt purge golang
$ sudo apt autoremove
$ go version
// should not working now
$ sudo apt list --installed | grep go
// See if it is all gone