Google has gained quite a reputation over the years for producing a range of innovative and interesting projects. Some of these have gone on to be adopted and marketed by Google themselves and others that have branched off to be their own corporations.
This innovation has been fuelled by Google’s 20% time initiative where alongside their normal work, engineers have been permitted to work on their own personal projects for 20% of their working week. One project, more than others, has come from Google innovations. The one that has had a reasonable impact in the world of the development: The Go programming language.
Go was developed by three engineers, Robert Griesemer, Rob Pike and Ken Thompson, who were looking for a way to improve upon C++’s complexity and provide a language that functioned for the type of software they were working on at Google. If those names feel familiar, don’t be surprised. Ken Thompson is one of the founders of the UNIX operating system. Rob Pike worked with Thompson and Plan 9 at Bell Labs to create the language. Robert Griesemer was responsible for the Java HotSpot compiler; so quite an awesome trio
What is Go?
Go provides a C style language that offers better features for code concurrency. This allows programmers to run multiple concurrent tasks easily from within the same program. From an original release in 2009, Go is now the programming language used for a number of Google’s internal systems. Having gained popularity outside of Google, a number of projects now use Go including Docker and Canonical’s Juju system.
To find the answers to all of your Linux questions, make sure that you visit this page. Your command line life will get easier, we promise.
Installing Go is fairly simple as most Linux distributions include it in the default repositories. The only downside is that the repositories generally lag behind the current releases. At the moment CentOS, Debian and Ubuntu are all providing Go 1.6 while 1.8 is the current stable release. So if you need anything newer you’ll need to install from source. We’ll take you through both methods now.
First, to install the version from the repositories for Debian and Ubuntu you can use:
sudo apt-get update
sudo apt-get install golang-go
To install from the repositories on RedHat and CentOS:
sudo yum install golang
Once complete, the last thing you’ll need to do is set a GOPATH that Go can use when fetching and building software. To do this create the following new file:
sudo nano /etc/profile.d/golang.sh
Then paste in the following:
Save and exit the file, and that’s pretty much all you need to do to get Go installed. You can change the GOPATH to be something you’d prefer on your system if you have a preference.
If you want the latest version, you’ll need to start by downloading the latest archive:
Extract the files from the archive with:
tar -zxvf go1.8.1.linux-amd64.tar.gz
The archive contains pre-compiled binaries for Linux so you just need to change ownership of the extracted go directory to root and then move it to /usr/local (the recommended install location).
sudo chown -R root:root ./go
sudo mv go /usr/local/
Go is now in place ready to use. You just need to set the path that the system needs to use to find it’s binaries. To do this we’ll create a file in /etc/profile.d to add this to the path for all users of the system.
sudo nano /etc/profile.d/golang.sh
In this file you will want to paste the following lines:
You can save and exit that file now. Unfortunately, that file won’t have an effect until the system reboots. To get things working for your current session you can paste those lines in again to your command prompt and hit ‘Enter’.
You should now be able to use Go. To test enter the following command.
This will run Go and print the details of the installed version to the screen. The results should look something like this:
go version go1.8.1 linux/amd64
If Go responded as expected, you now have Go installed and working on your server ready for use.