Go (Golang) is a statically typed, compiled systems programming language developed by Google. Its primary design goals are simplicity, fast compilation, and excellent concurrency support through goroutines and channels. Go compiles to a single statically linked binary with no runtime dependencies — deploying a Go application means copying a single binary to the target server. This makes Go exceptionally attractive for microservices, CLI tools, infrastructure software (Docker, Kubernetes, Prometheus, Terraform are all written in Go), and high-performance web APIs. Go’s standard library includes a production-ready HTTP server, meaning many Go web applications require no external web framework at all. This guide covers installing Go 1.22 on RHEL 9, configuring the Go workspace, and building your first Go web application.
Prerequisites
- RHEL 9 with sudo/root access
Step 1 — Install Go
GO_VERSION="1.22.5"
cd /tmp
curl -LO "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz"
# Verify the SHA256 checksum (get from https://go.dev/dl/)
sha256sum go${GO_VERSION}.linux-amd64.tar.gz
# Install Go to /usr/local/go
rm -rf /usr/local/go
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
Step 2 — Configure the Go Environment
# /etc/profile.d/go.sh
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
source /etc/profile.d/go.sh
go version
go env
Step 3 — Create a Go Module Project
mkdir -p /var/www/mygoapp && cd /var/www/mygoapp
# Initialise a Go module
go mod init github.com/mycompany/mygoapp
# Install a web framework (gin is the most popular)
go get github.com/gin-gonic/gin
Step 4 — Write a Go Web Application
# main.go
package main
import (
"net/http"
"os"
"github.com/gin-gonic/gin"
)
func main() {
gin.SetMode(gin.ReleaseMode)
r := gin.New()
r.Use(gin.Recovery())
r.Use(gin.Logger())
r.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})
r.GET("/api/items", func(c *gin.Context) {
items := []gin.H{
{"id": 1, "name": "Item One"},
{"id": 2, "name": "Item Two"},
}
c.JSON(http.StatusOK, gin.H{"items": items})
})
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
r.Run(":" + port)
}
Step 5 — Build and Deploy
cd /var/www/mygoapp
# Download dependencies
go mod tidy
# Build the binary (single static binary)
go build -o mygoapp .
ls -lh mygoapp
# Cross-compile for Linux from macOS/Windows
GOOS=linux GOARCH=amd64 go build -o mygoapp-linux .
# Run
./mygoapp &
curl http://localhost:8080/health
Step 6 — Create a systemd Service
# /etc/systemd/system/mygoapp.service
[Unit]
Description=My Go Application
After=network.target
[Service]
User=goapp
Group=goapp
ExecStart=/var/www/mygoapp/mygoapp
Restart=always
Environment=PORT=8080 GIN_MODE=release
[Install]
WantedBy=multi-user.target
useradd -r -s /bin/false goapp
chown goapp:goapp /var/www/mygoapp/mygoapp
systemctl daemon-reload && systemctl enable --now mygoapp
Conclusion
Go 1.22 on RHEL 9 produces self-contained statically linked binaries that require no runtime environment on the target server — the entire application and its dependencies are compiled into a single executable. This makes Go deployments significantly simpler than Python (no virtualenv), Node.js (no node_modules), or Java (no JVM) deployments. For high-performance HTTP APIs, Go’s concurrency model (goroutines) handles tens of thousands of simultaneous connections efficiently without the thread-per-connection overhead of Java or PHP models.
Next steps: How to Build and Deploy a Go Web Application on RHEL 9, How to Install Docker on RHEL 9, and How to Install Prometheus on RHEL 9.