This guide assumes you are using Ubuntu Linux 16.04 (Xenial) but will most likely work for setting up a Go development environment on other versions of linux. You can still follow this guide if you are using OSX but some small things will differ such as the binary to download. You could always run Go on Linux in a Virtual Machine with Virtual Box.
To begin we need to head over to the Go downloads page. The latest release when writing this article is go 1.10.1 and is what I will use. Your links and filenames will differ if you pick a different version. Before starting you should run
sudo apt-get updateto make sure we get the latest version of packages we install.
Click on a link or use
wget https://dl.google.com/go/go1.10.1.linux-amd64.tar.gz to download the version you would like to install. If you are not sure which version you need simply go with the stable version. It is fairly easy to switch versions later on.
Now let’s extract the files from the tar file we downloaded using the following command:
sudo tar -xvf go1.10.1.linux-amd64.tar.gz. Now you can decide where you want to copy your go files. This will be the “program” that is go so to speak and needs to be in your path. I personally prefer to put the files in
/usr/local/ and I recommend that you do this as well unless you have a reason to do otherwise. So we simply move our folder using
sudo mv ./go /usr/local
You should now be able to type
go version and it should print the version you just downloaded and moved. In my case the version shows as 1.10.1. We also need to set up our paths for go binaries so that they can be run from the terminal. Edit our profile file in the home directory,
~/.profile. Add the following to the bottom of the file if it is not already there:
export PATH=$PATH:/usr/local/go/bin and then run
source ~/.profile to reread this file and apply these new changes to your terminal session. In the future the
.profile will be read automatically when you use a terminal.
Now we need to setup a working directory. You can call this whatever you would like or follow my example like so:
mkdir $HOME/goprojects. Now we need to add this as our GOPATH so open your .profile file again and add
export GOPATH=$HOME/goprojects at the end of the file. Any projects you work on should now be placed under the following structure
Recommended Go IDE
Now we are ready to start editing code. There is no requirement to use an IDE and I know many who prefer something simple such as Sublime Text. However, when it comes to larger Go projects I prefer something more robust and my go to choice is GoLand.
GoLand comes from Jetbrains and you may have read my previous review of PHPStorm which is another IDE they make for PHP. I really like their software and have a All Products Pack subscription for all of their software. This subscription starts at 25 euro and is reduced for each consecutive year you keep the subscription active. Please note that I am not affiliated with Jetbrains, I am not being paid to write this and there are no affiliate links in this post. I just like their software and would recommend it.
Now as to why I like to use GoLand. It really helps with the small things such as automatically letting you know when you are missing a package and downloading it. Coding assistance is really useful with hints for variables and functions. You might think you don’t need it, I probably don’t but it’s a quality of life thing that makes my work easier to do. There are also many community plugins available that can help you extend this IDE when needed.
That’s the end of my post. I hope this helps you get going with Go and that you find it interesting to use. It is one of my favorite programming languages and I am still learning. I will try to write another guide for Mac OS and possible for Windows if I can get go to work there! I would love to hear your comments and feedback.
Image credit: https://github.com/egonelbre/gophers