Learn How To Install Golang 1.8.3 on CentOS 7, Ubuntu 16.04, and Debian 9

February 1, 2020

Table of Contents

Golang is a programming language developed by Google. Thanks to its versatility, simplicity and reliability, Golang has become one of the most popular programming languages in the open source community.

In this article, I will show you how to install the latest stable release of Golang on 64-bit and 32-bit Linux operating systems, including CentOS 7, Ubuntu 16.04 LTS, and Debian 9 Stretch. At the time I wrote this article, the latest stable release of Golang was Golang 1.8.3.

Prerequisites

  • An ITWeb.Services CentOS 7, Ubuntu 16.04 LTS, or Debian 9 Stretch linux server instance.
  • A sudo user.

Step 1: Download and decompress the Golang 1.8.3 archive

For 64-bit Linux operating systems

If you are using a 64-bit Linux operating system, including CentOS 7 x64, Ubuntu 16.04 amd64, and Debian 9 amd64, you need to download the 64-bit version of Golang as below:

cd
wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
sudo tar -zxvf go1.8.3.linux-amd64.tar.gz -C /usr/local

For 32-bit Linux operating systems

If you are using a 32-bit Linux operating system, including Ubuntu 16.04 i386 and Debian 9 i386, you need to download the 32-bit version of Golang as below:

cd
wget https://storage.googleapis.com/golang/go1.8.3.linux-386.tar.gz
sudo tar -zxvf go1.8.3.linux-386.tar.gz -C /usr/local

Note: You can always find the download link to the latest release of Golang on the official download page.

Step 2: Setup GOROOT and PATH environment variables:

echo 'export GOROOT=/usr/local/go' | sudo tee -a /etc/profile
echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee -a /etc/profile
source /etc/profile

Step 3: Test the installation

go version
go env

In addition, you can write a simple Golang program and give it a shot:

cd
mkdir -p src/hello
cd src/hello
vi hello.go

Populate the file ~/src/hello/hello.go with the following code segment:

package main

import "fmt"

func main() {
    fmt.Printf("hello, worldn")
}

Save and quit:

:wq!

Finally, run your first Golang program as follows:

go run hello.go

If everything was done correctly, you will see the output:

hello world

This concludes my tutorial. Thanks for reading.

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!