Installing Go (Golang) can be tricky on Ubuntu. The repositories for versions 12.04 and 14.04 are dated and install an older version of Go.
Luckily, there is a tool called the Go Version Manager (gvm) to help install, maintain, and even switch Go versions. I know it can be a little scary not using apt-get or aptitude, but in this case, it is worth it.
The installation process simply involves a clone of a GitHub repo and a single line in your .bashrc.
1. Clone the Repo and Add to User Directory
This command uses cURL to grab the GitHub repo and install it within your user directory. The file that this repo is placed in is ~/.gvm.
2. Open Your ~/.bashrc and Source the GVM Directory[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
All we are doing here is linking the gvm binary to our environmental variables. This allows you to run GVM from any path on your command line.
3. Logout and Login with Your User
The easiest way to make the changes in your .bashrc take effect is to just log out and log back into your shell.
4. Check to Make Sure that GVM is Installed$ gvm version Go Version Manager v1.0.22 installed at /home/myuser/.gvm
This command will tell you which version of GVM is installed. If it reports a version back, then you have successfully installed GVM. Well done!
5. Install Go (Golang)
First let’s check the versions of Go that are available.$ gvm listall ... go1.2rc5 go1.3 go1.3.1 go1.3.2 go1.3.3 go1.3beta1 go1.3beta2 go1.3rc1 go1.3rc2 go1.4 go1.4beta1 go1.4rc1 go1.4rc2
As you can see, GVM includes the beta versions of software and release candidates (rc).
Let’s install Go 1.4.$ gvm install go1.4 Downloading Go source... Installing go1.4... * Compiling...
6. Tell GVM Which Version of Go to Use
Now that we have Go installed on our system, let’s let GVM know we wish to use that version.$ gvm use go1.4 Now using version go1.4
Sweet. Everything is going great so far.
7. Verify Go Is Installed Correctly$ go version go version go1.4 linux/amd64
We are done! GVM makes this process simple, and upgrading, changing versions, and uninstalling Go is now simple as well.
Update: Installing Go 1.5 Might Take an Additional Step
Go has changed how they compile their source and it has caused some issues with gvm. This is reported as fixed but I figured we should mention it just in case. Basically, just install go1.4 before you install go1.5.
gvm install go1.4 gvm use go1.4 export GOROOT_BOOTSTRAP=$GOROOT gvm install go1.5
Have fun, and as usual, feel free to ask any questions below.
HostingAdvice.com is a free online resource that offers valuable content and comparison services to users. To keep this resource 100% free, we receive compensation from many of the offers listed on the site. Along with key review factors, this compensation may impact how and where products appear across the site (including, for example, the order in which they appear). HostingAdvice.com does not include the entire universe of available offers. Editorial opinions expressed on the site are strictly our own and are not provided, endorsed, or approved by advertisers.
Our site is committed to publishing independent, accurate content guided by strict editorial guidelines. Before articles and reviews are published on our site, they undergo a thorough review process performed by a team of independent editors and subject-matter experts to ensure the content’s accuracy, timeliness, and impartiality. Our editorial team is separate and independent of our site’s advertisers, and the opinions they express on our site are their own. To read more about our team members and their editorial backgrounds, please visit our site’s About page.