Installing and Setting Up Go on Linux

Hands-On Lab

 

Photo of Keith Thompson

Keith Thompson

DevOps Training Architect II in Content

Length

01:00:00

Difficulty

Beginner

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.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Installing and Setting Up Go on Linux

Introduction

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.

Solution

  1. Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

    ssh cloud_user@PUBLIC_IP_ADDRESS

Download and Install Go

  1. Log in as root

    sudo su - root
  2. Navigate to the temp directory.

    cd /tmp/
  3. On the Linux Academy lab page, navigate down to the Objectives and expand the first objective. Open the link to the Go downloads page in a new tab.

  4. Copy the link address for the linux-amd64 file.

  5. Back in the lab server, download the file. Remember to supply the link copied in the previous step.

    curl -o LINUX-AMD64-FILE-LINK
  6. Unarchive the files, using the filename of the archive.

    tar -C /usr/local -xzf ARCHIVE-FILENAME
  7. Verify the existence of the path /usr/local/go.

Set up the $GOPATH and Modify $PATH to Include Go Binaries

  1. Exit from being the root user.

    exit
  2. Make a directory for Go as well as some subdirectories.

    mkdir -p go/{src,bin}
  3. Edit the bashrc.

    vim .bashrc
  4. Add the path to the bottom of the bashrc file.

    export GOPATH=$HOME/go
    export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
  5. Save the file.

  6. Reload the shell.

    exec $SHELL
  7. Test the new paths by checking the Go version.

    go version
  8. Attempt to run the sample program provided.

    go run ~/hello.go

Install Git

  1. Install Git.

    sudo yum install -y git

Conclusion

Congratulations — you've completed this hands-on lab!