
In this tutorial, we will show you how to install and compile Go, as well a run a basic Go program on a CentOS 7 VPS.

Go, also known as Golang, is an open-source programming language developed by Google. Go provides an easy way to build simple, reliable, and efficient software. Go is a system programming language designed for speed and simplicity. You can compile a single go program and an executable that will run on Windows, macOS, and Linux, without making any changes to your code. This cross-platform compatibility makes Go an attractive option for developers that only want to code once.
Let’s get started with the installation.
Table of Contents
Prerequisites
- A CentOS 7 VPS with root access enabled, or a user with sudo privileges.
Step 1: Log in and Update Packages
First, we’re going to need to log into our server using SSH. You can do that by entering this command:
Remember to replace “root” with your username if you are not using the root user. Change “IP_Address” and “Port_Number” according to your server’s IP address and SSH port number.
Once you are logged in, you should update all of your packages to their latest available versions.
Once all the packages are up-to-date, restart your server to apply the configuration changes.
Step 2: Download and Install Go
First, you will need to download the latest version of the Go tarball from the Go official website. At the time of writing this article, the latest stable version of Go is version 1.12.7.
To download the Go tarball, run the following command:
Once the tarball is downloaded, verify the tarball checksum with the following command:
You should see an output that looks similar to the one below:
Compare the hash value from the above output to the checksum value on the Go download page. If they match that means the integrity of the file validated and you can proceed with the installation.
Next, extract the downloaded file to the /usr/local
directory with the following command:
Step 3: Edit the Path Variable for Go
Next, we will need to set up the Go path environment variable to execute Go like any other command, no matter where you are in the filesystem.
You can set the environment variable globally by creating a file called go.sh
in the /etc/profile.d
directory.
Add the following line:
Save and close the file when you have finished.
If you want to set the Go path environment variable for a specific user, then you will need to define Go environment variables in your user’s .bash_profile
file.
Add the following lines:
Save and close the file. Then, run the source command to reload the updated profiles:
Next, verify the Go installation with the following command:
You should see the following output:
Step 4: Create your First Go Project
Here we will create a sample program in the Go language. First, create a new directory for the Go workspace with the following command:
Next, create a new src/test directory inside $HOME/project with the following command:
Next, create a simple program (test.go) with the following command:
Add the following content:
Save and close the file. Then, compile the program with the following command:
The above command will generate an executable named test. You can now run the program with the following command:
The output should be similar to the one below:
That’s it! Now you can use Go to code your programs for any platform.
In this tutorial, we learned how to install Go on a CentOS 7 VPS. We also learned how to set up the Go environment variable and create a Go program.
Of course, you don’t need to do any of this if you use one of our managed Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Go on CentOS 7 for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on how to install Go on CentOS 7, please share it with your friends on the social networks using the buttons below, or simply leave a reply down in the comments section. Thank you.