Go (also called Golang) is a statically typed, compiled language designed for simplicity and performance, making it an excellent choice for building web services, CLI tools, and DevOps utilities on Linux servers. Unlike interpreted runtimes, Go compiles to a single self-contained binary with no external dependencies, which simplifies deployment significantly. In this tutorial you will download the official Go toolchain from go.dev, install it on RHEL 8, configure your environment, and write and run a small web server to confirm everything is working correctly.

Prerequisites

  • RHEL 8 (or a compatible distribution such as AlmaLinux 8 or Rocky Linux 8) with sudo access
  • At least 512 MB of free disk space in /usr/local for the Go toolchain
  • Internet access to download the Go binary from go.dev
  • wget or curl installed (sudo dnf install -y wget)

Step 1 — Download the Go Toolchain

Always download Go from the official site to ensure you get the latest stable release with security patches. Check https://go.dev/dl/ for the current version number before running these commands:

GO_VERSION=1.22.3
wget -q https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz -O /tmp/go.tar.gz

# Verify the download completed and has a reasonable file size
ls -lh /tmp/go.tar.gz

For production servers it is good practice to also verify the SHA-256 checksum published on the Go download page before extracting.

Step 2 — Install Go to /usr/local

The Go documentation recommends installing to /usr/local/go. If a previous Go installation exists there, remove it first to avoid mixing versions:

sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf /tmp/go.tar.gz
ls /usr/local/go/bin/

You should see go and gofmt in that directory. The archive extracts into a go/ subdirectory automatically, so the final toolchain path is /usr/local/go.

Step 3 — Configure Environment Variables

Add the Go binary directory to the system PATH for all users by creating a profile drop-in script, and set the GOPATH for your own user workspace:

sudo tee /etc/profile.d/go.sh <> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc

GOPATH is where go install places compiled binaries and where older-style (pre-modules) source trees live. For module-based projects you rarely need to think about it, but having $GOPATH/bin on your PATH is useful for tools installed with go install.

Step 4 — Verify the Installation

Confirm the Go toolchain is accessible and reports the expected version:

go version
go env GOPATH
go env GOROOT

The output of go version should be go version go1.22.3 linux/amd64. GOROOT points to /usr/local/go (the installed toolchain) and GOPATH points to ~/go (your workspace).

Step 5 — Initialize a Module and Write a Simple Web Server

Go modules are the standard way to manage dependencies. Create a new project directory, initialize a module, and write a minimal HTTP server using the standard library:

mkdir -p ~/gowebtest && cd ~/gowebtest
go mod init example.com/gowebtest

cat > main.go << 'EOF'
package main

import (
    "fmt"
    "log"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintln(w, "Hello from Go on RHEL 8!")
}

func main() {
    http.HandleFunc("/", handler)
    log.Println("Listening on :8080")
    log.Fatal(http.ListenAndServe(":8080", nil))
}
EOF

Step 6 — Build and Run the Application

Build the project into a binary and test it. You can also install it to $GOPATH/bin for system-wide access:

go build -o gowebtest .
./gowebtest &

curl http://localhost:8080/
kill %1

# Install the binary to $GOPATH/bin
go install example.com/gowebtest

The compiled binary has no runtime dependencies — you can copy it to any RHEL 8 machine (or any Linux/amd64 machine) and run it without installing Go. This is one of Go’s most practical deployment advantages over interpreted languages.

Conclusion

You have downloaded and installed the Go toolchain on RHEL 8, configured the necessary environment variables system-wide and per-user, verified the installation, initialized a Go module, and compiled and ran a working HTTP server. The resulting binary is fully self-contained and ready to deploy anywhere. From here you can explore Go’s rich standard library, add external dependencies with go get, and package your applications as systemd services for production deployments.

Next steps: How to Build and Deploy a Go Web Application on RHEL 8, How to Deploy a Spring Boot Application on RHEL 8, and How to Install Python 3 and Set Up a Virtual Environment on RHEL 8.