How to Install Go on CentOS 7

Install Go on CentOS 7

In this tutorial we are going to learn how to install Go on CentOS 7. We will also install and configure its prerequisites. Go also understand as Golang, is an open source programming language developed by Google. Many popular programs, including Grafana, Docker and Kubernetes, are written in Go.

I recommend to use a minimal CentOS server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Go on CentOS 7

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

yum -y install epel-release
yum -y update

Step 2. Installing Go on CentOS 7.

First, download the Go binary you can use either wget or curl:

wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz

Now extract the downloaded archive and install it to the desired location on your system:

sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz

Then add it to your path:

export PATH=$PATH:/usr/local/go/bin

Save the file, and load the new PATH environment variable into the current shell session:

source ~/.bash_profile

At this step, you have successfully installed and configured go language on your system. First, use the following command to check Go version:

go version

Step 3. Test the Installation.

To test whether Go is installed, we will set up a workspace and build a simple “Hello world” program:

mkdir ~/go
mkdir -p ~/go/src/hello

And in that directory create a file named hello.go:

### ~/go/src/hello/hello.go
package main

import "fmt"

func main() {
    fmt.Printf("Hello, World\n")
}

Next, build the file switch to the ~/go/src/hello directory and run go build:

cd ~/go/src/hello
go build

Then, run the executable by simply executing the command bellow:

./hello

Result:

Hello, World

Congratulation’s! You have successfully install Go on your CentOS 7 server. Thanks for using this tutorial for installing Go language on CentOS 7 system.

How to Install Go on Debian 9

Install Go on Debian 9

In this tutorial we are going to learn how to install Go on Debian 9. We will also install and configure its prerequisites. Go also understand as Golang, is an open source programming language developed by Google. Many popular programs, including Grafana, Docker and Kubernetes, are written in Go.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Debian 9 Stretch minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Go on Debian 9

Step 1. First, before we install packages, it’s a good idea to update repository and software packages. Run the following command on your Debian 9 OS:

sudo apt update
sudo apt upgrade

Step 2. Installing Go on Debian 9.

First, download the Go binary you can use either wget or curl:

wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz

Next, use tar to extract the tarball to the /usr/local directory:

sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz

Then add it to your path:

export PATH=$PATH:/usr/local/go/bin

Save the file, and load the new PATH environment variable into the current shell session:

source ~/profile

As the final test, if we run this:

go version

Step 3. Test the Installation.

To test whether Go is installed, we will set up a workspace and build a simple “Hello world” program:

mkdir ~/go
mkdir -p ~/go/src/hello

And in that directory create a file named hello.go:

### ~/go/src/hello/hello.go

package main
import "fmt"
func main() {
fmt.Printf("Hello, World\n")
}

Next, build the file switch to the ~/go/src/hello directory and run go build:

cd ~/go/src/hello
go build

Then, run the executable by simply executing the command bellow:

./hello

Result:

Hello, World

Congratulation’s! You have successfully install and configured Golang on your Debian Stretch. Thanks for using this tutorial installing Go data bases on Debian 9 (Stretch) system.

How to Install Go on Ubuntu 18.04

Install Go on Ubuntu 18.04

In this tutorial we are going to learn how to install Go on Ubuntu 18.04. We will also install and configure its prerequisites. Go also understand as Golang, is an open source programming language developed by Google. Many popular programs, including Grafana, Docker and Kubernetes, are written in Go.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 Bionic Beaver minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Go on Ubuntu 18.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing Go on Ubuntu 18.04.

First, download the Go binary you can use either wget or curl:

wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz

Next, use tar to extract the tarball to the /usr/local directory:

sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz

Then add it to your path:

export PATH=$PATH:/usr/local/go/bin

Save the file, and load the new PATH environment variable into the current shell session:

source ~/profile

As the final test, if we run this:

go version

Step 3. Sample Go Application.

We will make our sample application something systems related. This sample application will be a simple app to show you the system time:

nano gettime.go

Put in the following contents:

package main

import (
        "fmt"
        "time"
)

func main() {
        fmt.Println(time.Now())
}

Go is a compiled language so we need to compile our code to a native executable:

go build gettime.go

Then, will now have an executable in your current directory that you can run:

$ ./gettime
2018-06-12 20:46:16.774145422 +0000 UTC m=+0.000132589

Congratulation’s! You have successfully install and configured Go on your Ubuntu 18.04 server. Thanks for using this tutorial installing Go open source programming language on Ubuntu 18.04 LTS (Bionic Beaver) system.