Last updated on October 9, 2020 by Dan Nanni
Go (also called golang
) is an open-source programming language initially developed by Google. It was born with several design principles in mind: simplicity, safety, and speed. The Go language distribution comes with various tools for debugging, testing, profiling and code-vetting. Nowadays the Go language and its tool chain are available in the base repositories of most Linux distributions, allowing you to install them with a default package manager. However, note that your distro's repository may provide a little bit outdated version. If you need the latest version of Go, install it from the official website. This tutorial describes both ways to install Go and its tool chain.
The following apt-get
command will install Go language and its development tools on Debian-based distributions.
$ sudo apt-get install golang
Check the version of Go language to verify installation.
$ go version
go version go1.2.1 linux/amd64
Since Go code must be kept inside a workspace, create a workspace directory in your home directory (e.g., ~/go
). This is where the Go tool builds source packages and installs the binaries.
$ mkdir ~/go
Then set up Go related environment variables system-wide as follows.
$ sudo vi /etc/profile.d/goenv.sh
export GOROOT=/usr/lib/go export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ source /etc/profile.d/goenv.sh
Depending on your need, you may want to install additional Go tools using apt-get
.
$ sudo apt-cache search golang
The following yum
command will install Go language and its development tools on Red Hat based distributions.
$ sudo yum install golang
Check the version of Go language to verify installation.
$ go version
go version go1.3.3 linux/amd64
Next, create a workspace directory in your home directory (e.g., ~/go
), which is where the Go tool builds source packages and installs the binaries. Then define Go related environment variables.
$ mkdir ~/go
$ sudo vi /etc/profile.d/goenv.sh
export GOROOT=/usr/lib/golang export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ source /etc/profile.d/goenv.sh
Depending on your need, you can install additional Go tools using yum
.
$ yum search golang
Sometimes the version of Go language that comes with your Linux distribution may not be up-to-date. In that case, you can install the latest Go language from its official website. Here is how you can do it.
Go to the official source of Go language, and download pre-built binaries.
$ wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz
$ wget https://storage.googleapis.com/golang/go1.4.1.linux-386.tar.gz
Install the binaries under /usr/local
.
$ sudo tar -xzf go1.4.1.linux-xxx.tar.gz -C /usr/local
Create a workspace directory in your home directory (e.g., ~/go
), and define Go related environment variables system-wide as follows.
$ mkdir ~/go
$ sudo vi /etc/profile.d/goenv.sh
export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ source /etc/profile.d/goenv.sh
Check the version of Go language.
$ go version
go version go1.4.1 linux/amd64
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean