Getting started with any programming language requires some initial setup, and Go is no different. Occasionally, the setup of compiled languages can be tricky, but thankfully Go has a fairly painless setup. In this learning activity, you’ve been asked to set up a development server for your boss who wants to learn Go but doesn’t want to go through the setup. By the time you’ve finished this activity, you should feel comfortable setting up a Go development environment.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Download and install Go (version 1.11.x)
To install Go, we need to download the package for our server’s operating system and CPU architecture from the Go downloads page. The server we’ve been given is running 64-bit Linux, so we’ll need the
linux-amd64
version.After the package is downloaded, it should be extracted and moved to
/usr/local
. Here’s one way we can achieve this for version1.11.2
:~ $ cd /tmp /tmp $ wget https://dl.google.com/go/go1.11.2.linux-amd64.tar.gz /tmp $ sudo tar -C /usr/local -xzf go1.11.2.linux-amd64.tar.gz
We’ll also want to install
git
:~ $ sudo yum install -y git
- Set up the `$GOPATH`
When developing with Go, the source code needs to be placed in the
$GOPATH
, and that directory tree needs to be manually set up. We need to create the directories at~/go
,~/go/bin
, and~/go/src
. Once these directories are set up, then we’ll also need to set up the$GOPATH
environment variable.~ $ mkdir -p ~/go/{src,bin} ~ $ echo 'export GOPATH=$HOME/go' >> ~/.bashrc
- Modify `$PATH` to include Go binaries
The Go package we downloaded comes with its own binaries, but we won’t have access to them until they are placed within our
$PATH
. We need to append the/usr/local/go/bin
and$GOPATH/bin
directories to our$PATH
in the.bashrc
file./tmp $ cd ~ ~ $ echo 'export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin' >> ~/.bashrc ~ $ source .bashrc ~ $ go run hello.go Thank you for setting up this server! ~ $