Go is a statically typed, compiled language from Google that excels at building fast, reliable command-line tools and network services. On RHEL 9, the system repositories may not carry the latest Go release, so installing from the official tarball is the recommended approach. This tutorial walks through downloading Go 1.22+, configuring the environment system-wide, and building a real CLI tool complete with sub-commands and cross-compilation support.

Prerequisites

  • RHEL 9 server with a non-root user that has sudo privileges
  • Internet access to reach go.dev
  • Basic familiarity with the Bash shell

Step 1 — Download the Go Tarball

Visit go.dev/dl/ to confirm the latest stable version, then download it directly to your server. At the time of writing, Go 1.22 is the current stable release.

curl -LO https://go.dev/dl/go1.22.3.linux-amd64.tar.gz
sha256sum go1.22.3.linux-amd64.tar.gz

Compare the checksum printed against the value shown on the Go download page before proceeding.

Step 2 — Extract Go and Set the System PATH

Remove any previous Go installation and extract the new tarball into /usr/local.

sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.22.3.linux-amd64.tar.gz

Create a profile script so every user on the system inherits the Go binary path on login.

sudo tee /etc/profile.d/go.sh <<'EOF'
export PATH=$PATH:/usr/local/go/bin
EOF
sudo chmod 644 /etc/profile.d/go.sh
source /etc/profile.d/go.sh

Verify the installation and set a per-user workspace:

go version
# go version go1.22.3 linux/amd64

mkdir -p $HOME/go/{bin,src,pkg}
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc

Step 3 — Initialise a Module and Write a CLI Tool

Go modules are the standard dependency management system since Go 1.11. Create a new project directory and initialise a module.

mkdir -p ~/projects/mycli && cd ~/projects/mycli
go mod init github.com/youruser/mycli

Write a minimal CLI using the standard flag and os packages — no third-party dependency required.

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

import (
    "flag"
    "fmt"
    "os"
)

func main() {
    greetCmd := flag.NewFlagSet("greet", flag.ExitOnError)
    name := greetCmd.String("name", "world", "Name to greet")

    if len(os.Args) < 2 {
        fmt.Println("Usage: mycli  [options]")
        fmt.Println("Commands: greet")
        os.Exit(1)
    }

    switch os.Args[1] {
    case "greet":
        greetCmd.Parse(os.Args[2:])
        fmt.Printf("Hello, %s!n", *name)
    default:
        fmt.Printf("Unknown command: %sn", os.Args[1])
        os.Exit(1)
    }
}
EOF

Step 4 — Build and Install the Binary

Compile a release binary and install it system-wide so it is available from any directory.

go build -o mycli ./...
./mycli greet --name RHEL9

# Install to a shared location
sudo go build -o /usr/local/bin/mycli ./...
mycli greet --name "RHEL 9 Server"

Step 5 — Cross-Compile for Other Architectures

One of Go’s most useful features is first-class cross-compilation. Build an ARM64 binary from your x86_64 RHEL 9 host without any additional toolchain.

# Build for 64-bit ARM (e.g., AWS Graviton, Raspberry Pi 4)
GOOS=linux GOARCH=arm64 go build -o mycli-arm64 ./...

# Build for Windows amd64
GOOS=windows GOARCH=amd64 go build -o mycli.exe ./...

file mycli-arm64
# mycli-arm64: ELF 64-bit LSB executable, ARM aarch64

Step 6 — Install Community Tools with go install

The go install command downloads, compiles, and places third-party binaries directly into $GOPATH/bin. This is the idiomatic way to install Go-based developer tools.

# Install golangci-lint — a fast Go linter aggregator
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

# Install gopls — the official Go language server
go install golang.org/x/tools/gopls@latest

# Install staticcheck — advanced static analysis
go install honnef.co/go/tools/cmd/staticcheck@latest

# Verify tools are available
which golangci-lint
golangci-lint --version

Run the linter against your project:

cd ~/projects/mycli
golangci-lint run ./...

Conclusion

You have installed Go 1.22 from the official tarball on RHEL 9, configured a system-wide PATH, built and installed a CLI tool with sub-commands, cross-compiled binaries for ARM64 and Windows, and installed community tooling with go install. Your RHEL 9 system is now a capable Go development environment.

Next steps: How to Install Rust and Compile System Tools on RHEL 9, How to Install Java and Configure JAVA_HOME on RHEL 9, and How to Deploy a .NET Application on RHEL 9.