How to Install Go on CentOS 8

Install Go on CentOS 8

In this article, we will have explained the necessary steps to install and configure Go on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Go Lang (Golang) is an open source programming language developed by a team of Google engineers in 2007. Go language was designed to resolve the common criticisms of other languages while maintaining their positive characteristics and most widely used for writing servers these days.

Install Go on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Step 2. Install Go on CentOS 8.

Download the Go binary using the wget command:

Once the archive is downloaded, verify the tarball checksum:

Now extract the downloaded tarball using following command inside /usr/local directory:

Step 3. Set Go Path.

Next, edit the $PATH environment variable so that the system knows where the Go executable binaries are located. You can do this either by appending the following line to the /etc/profile file (for a system-wide installation) or to the $HOME/.profile file:

Save the file, and apply the new PATH environment variable to the current shell session by typing:

To verify that everything is working, run go version and see if the version is returned:

Check the Go environment variables we set in previous sections:

Step 4. Build Hello world Program in Go.

First, Create a new directory for go workspace by using following command:

Now create src directory inside it typing below command:

Next create hello.go file inside src/hello directory using below command:

Add following content:

Now go to the:

And build the program using following command:

The output should look like this:

Congratulation, you have learned how to install and configure Go on CentOS 8. If you have any question, please leave a comment below.