How to install Go lang on Rocky Linux

Endrit Qerreti

Endrit Qerreti

If you are a Go developer, and need to be able to code in Go on your Rocky Linux system, then all you need is Go installed on your machine.

Installing Go programming language on Rocky Linux is quite easily, and you can do so by downloading Go from the official Go website.

In this tutorial, you will learn how to install Go programming language on Rocky Linux.

Step 1 - Update Rocky Linux system

Before installing Go programming language on your Rocky Linux machine, you need to make sure that your system is up to date.

There are various ways to update Rocky Linux. However, in this tutorial, we'll be updating Rocky Linux directly from the terminal.

So all we need to do is run the command below.

sudo dnf update -y

Step 2 - Download Go on Rocky Linux

Now that your Rocky Linux machine is up to date, you can proceed to download Go.

Go can be easily downloaded via wget directly from the terminal.

To do so, simply run the command below.

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

Step 3 - Install Go on Rocky Linux

Now that Go source is downloaded on your Rocky Linux machine, you can proceed to install it.

In this tutorial, we are installing Go on Rocky Linux via source, so what we need to do is extract Go source in the /usr/local/ directory.

To do so, simply execute the command below.

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

Step 4 - Add Go to PATH Environment variable on Rocky Linux

Go programming language is now installed on your Rocky Linux system. In order to be able to use Go, first you must add Go to your path environment variable.

To add Go in the Path environment variable on Rocky Linux, simply run the command below.

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

Once you do that, you need to source your ~/.bashrc file so that changes take effect.

To do so, simply execute the command below.

source ~/.bashrc

Step 5 - Verify Go installation on Rocky Linux

Go programming language is now installed on your Rocky Linux machine. Before you start using Go, first you need to verify that Go installation was done correctly.

To check if Go was installed correctly on your Rocky Linux system, run the command below.

go version

Step 5 - Create a simple Go app

Now that we know that we can use Go, let's create a simple Go app that we can run from the terminal.

1) Create an empty Go file.

sudo nano hello_world.go

hello_world.go is the name of the Go app that we are creating.

2) Add the code below into hello_world.go file.

package main
import "fmt"
func main() {
    fmt.Println("Hello from OwlHowTo")
}

Press CTRL +X to save changes, then press Y and then press Enter.

3) Run the Go app that we created.

go run hello_world.go

4) Build hello_world.go into a binary.

go build hello_world.go

5) Run hello_world.go binary.

./hello_world.go

Conclusion

In this tutorial, you learned how to install Go programming language on Rocky Linux, by downloading Go source from the official Go website.

We also showed you how to run Go apps via the terminal on Rocky Linux.