Install Go Language on AlmaLinux 8

In this guide, we want to teach you to Install Go Language or Golang on AlmaLinux 8.

Go, also known as Golang, is an open-source, compiled, and statically typed programming language designed by Google. It is built to be simple, high-performing, readable, and efficient.

Go is one of the simplest programming languages out there. It is easy to pick up, especially if you already have knowledge of any other programming language.

Steps To Install Go Language or Golang on AlmaLinux 8

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with AlmaLinux 8.

You can install Golang from both the Dnf package manager and from the source. Let’s see how to do it.

Install Golang Using DNF on AlmaLinux 8

Go language packages are available in the default AlmaLinux repository. You can easily use the DNF package manager to install it.

First, update your local package index with the command below:

sudo dnf update -y

Then, use the following command to install Golang on AlmaLinux 8:

sudo dnf install golang -y

This method is not in the latest version. You can proceed to the next step to install the latest version of Golang on your AlmaLinux server.

Install Golang From Source on AlmaLinux 8

At this point, you can follow the steps below t install the latest version of Go language.

Download Go From Source

Here you can visit the Go Downloads page and use the wget command to download the Tar file given for Linux:

sudo wget https://go.dev/dl/go1.20.1.linux-amd64.tar.gz

Then, extract your downloaded file in the /usr/local directory by using the command below:

sudo tar -xzf go*.linux-amd64.tar.gz -C /usr/local

Note: If you don’t have the tar package installed on your server, you can use the command below to install it:

sudo dnf install tar -y

When your extraction is completed, you can delete your downloaded file to free your space:

sudo rm go*.linux-amd64.tar.gz

Configure System Environment Path

At this point, you need to configure the system environment for Go by adding its folder usr/local/go/bin to your path.

Open the bashrc file by using your favorite text editor, here we use vi editor:

sudo vi ~/.bashrc

Add the following line at the end of the file:

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

When you are done, save and clsoe the file.

Next, reload your configuration file bu using the following command:

source ~/.bashrc

Verify your Go installation on AlmaLinux 8 by chekcing its version:

go version
Output
go version go1.20.1 linux/amd64

To get options and help of Go, you can run the command below:

go --help
Output
Go is a tool for managing Go source code.

Usage:

        go <command> [arguments]

The commands are:

        bug         start a bug report
        build       compile packages and dependencies
        clean       remove object files and cached files
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        get         add dependencies to current module and install them
        install     compile and install packages and dependencies
        list        list packages or modules
        mod         module maintenance
        work        workspace maintenance
        run         compile and run Go program
        test        test packages
...

Test Go Language

At this point, you can craete a test program with Go language to see it is working correctly.

Craete a sample hello world file by using your favorite text editor, here we use vi editor:

vi hello.go

Add the following content to the file:

package main 
import "fmt" 
func main () {
fmt.Printf( "hello world\n" )
}

When you are done, save and close the file.

Compile the program by using the following comamnd:

go build hello.go

Then, run your executable file:

./hello
Output
hello world

That’s it, you are done.

Conclusion

At this point, you have learned to Install Go Language or Golang on AlmaLinux 8. And you have learned to create a test program to see your Go language is working correctly.

Hope you enjoy it. You may be like these articles:

Install and Configure OpenNMS on AlmaLinux 8

Install FreeRADIUS and daloRADIUS on AlmaLinux 8

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *

Stay informed and not overwhelmed, subscribe now!