Installing and Setting Up Go on Linux

Get Started
1 hour
  • 3 Learning Objectives

About this Hands-on Lab

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 version 1.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!
~ $

Additional Resources

Go is a programming language that has been picking up speed for a few years, and your boss has noticed. He would like to have a server he can use to experiment with Go, but he doesn't want to take the time to set it up himself. You've been asked to install Go and set up the development environment on a server so he can simply log in and get to work. To ensure the environment is set up correctly, there is a Go file on the server you should be able to run with the following command:

$ go run ~/hello.go
What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?