How to Install Go (Golang) Compiler on Fedora 36 Linux

Go, or Golang, is an open-source programming language that Google created. It is statically typed and produces compiled machine code binaries, and go language is a compiled language. This is popular amongst developers as it means you do not need to compile the source code to create an executable file. Developers that use Google’s Go language say it is the C for the twenty-first century when it comes to syntax.

The following tutorial will teach you how to install and configure Go (Golang) on Fedora 36 Linux using the command line terminal with the default repository version from Fedora 36’s appstream.

Update Fedora

Before proceeding, ensure your system is up-to-date.

sudo dnf upgrade --refresh

Install Go (Golang)

By default, Fedora contains Golang. It is often the most recommended method to install the programming language as Fedora focuses on upstream releases. It is usually always up-to-date and is easiest to keep updated using the standard update commands.

Install Golang on your desktop or server using the following command.

sudo dnf install golang -y

Optionally, confirm the version installed on your system running the version command.

go version

Create a Golang Test Program – Verify Installation

Now that you have installed Go, we will create a small program to print (hello world).

First, create a directory using the following command.

mkdir go-hello

Now, you will create a (.go) file. The quickest way to do this is using the nano editor as follows.

nano go-hello/hello.go

Next, add the following text below to create the (Hello World) Go program.

package main

import "fmt"

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

Now, you need to build (go.mod) file so you can execute the Go file you just created!

sudo nano go-hello/go.mod

Add the following line.

module example.com/mod

Save the file (CTRL+O), then exit (CTRL+X).

Next, cd to the directory, then build the program by entering the following command.

cd go-hello && go build

Finally, execute the (Hello World) program by entering the following command.

./mod

Comments and Conclusion

Go is growing in popularity as more developers begin to see its potential. It’s an excellent language for web development, system programming, and network programming. If you want to learn this powerful language, plenty of resources online can get you started.

For more information on using and developing with Go, visit the official documentation.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!