
How to Install Go on Ubuntu 24
Installing Go on Ubuntu 24 is a fundamental task for developers looking to dive into one of today’s most popular programming languages for building scalable, concurrent applications. Whether you’re deploying microservices, creating CLI tools, or building web APIs, Go’s performance and simplicity make it an excellent choice for modern development. This guide walks you through multiple installation methods, from the official binary installation to package managers, while covering common pitfalls and optimization tips you’ll actually use in production environments.
Why Go on Ubuntu 24
Go’s lightweight runtime and excellent cross-compilation support make it particularly well-suited for server environments. Ubuntu 24 LTS provides the stability and long-term support that production Go applications need, especially when running on VPS or dedicated servers. The combination gives you a rock-solid foundation for everything from container orchestration tools to high-performance web services.
Here’s what makes this pairing compelling:
- Go’s garbage collector is optimized for low-latency applications
- Ubuntu 24’s improved systemd integration simplifies service management
- Native support for modern container runtimes and orchestration platforms
- Excellent toolchain compatibility with CI/CD pipelines
Installation Methods Comparison
You’ve got several ways to get Go running on Ubuntu 24, each with distinct advantages:
Method | Pros | Cons | Best For |
---|---|---|---|
Official Binary | Latest version, predictable, Google-signed | Manual updates, no package management | Production environments, specific version requirements |
APT Package | Automatic updates, integrated with system | Often outdated, limited version control | Quick setups, development environments |
Snap Package | Always current, sandboxed, auto-updates | Larger footprint, potential PATH issues | Desktop development, isolated environments |
Source Compilation | Complete control, optimization options | Time-consuming, requires existing Go | Custom builds, performance optimization |
Method 1: Official Binary Installation (Recommended)
This approach gives you the most control and ensures you’re running the exact version Google releases. It’s what most production environments use.
Step 1: Download and Verify
# Remove any existing Go installation
sudo rm -rf /usr/local/go
# Download the latest Go binary (check https://golang.org/dl/ for current version)
wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz
# Verify the checksum (get current hash from golang.org)
sha256sum go1.21.5.linux-amd64.tar.gz
Step 2: Extract and Install
# Extract to /usr/local
sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz
# Set up environment variables
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export GOBIN=$GOPATH/bin' >> ~/.bashrc
# Reload your shell configuration
source ~/.bashrc
Step 3: Verify Installation
# Check Go version and configuration
go version
go env GOROOT
go env GOPATH
# Test with a simple program
mkdir -p $GOPATH/src/hello
cd $GOPATH/src/hello
Create a test file:
cat << EOF > main.go
package main
import "fmt"
func main() {
fmt.Println("Hello, Ubuntu 24!")
}
EOF
go run main.go
Method 2: APT Package Installation
Quick and dirty for development environments where you don’t need the bleeding edge:
# Update package index
sudo apt update
# Install Go
sudo apt install golang-go
# Check what version you got
go version
# Set up workspace (still needed)
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export GOBIN=$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc
Method 3: Snap Installation
Snap packages stay current automatically, which is nice for development machines:
# Install Go via snap
sudo snap install go --classic
# Verify installation
go version
# The --classic flag gives Go the permissions it needs to work properly
Environment Configuration Best Practices
Getting your Go environment right from the start saves headaches later. Here’s the setup that works reliably across different deployment scenarios:
# Create a comprehensive Go environment setup
cat << 'EOF' >> ~/.bashrc
# Go environment
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin:$GOBIN
# Go module proxy (speeds up downloads)
export GOPROXY=https://proxy.golang.org,direct
export GOSUMDB=sum.golang.org
# Disable CGO for static binaries (optional)
# export CGO_ENABLED=0
EOF
# Create workspace directories
mkdir -p $HOME/go/{bin,src,pkg}
Performance Tuning and Optimization
Ubuntu 24 with Go can be optimized for different workloads. Here are some environment tweaks that make a difference:
# For high-concurrency applications
export GOMAXPROCS=$(nproc)
# Garbage collector tuning for low-latency apps
export GOGC=100 # Default, lower values = more frequent GC
export GOMEMLIMIT=1GiB # Set memory limit for GC
# Enable race detection during development
go run -race main.go
# Build optimized binaries for production
go build -ldflags="-s -w" -o myapp main.go
Common Issues and Troubleshooting
Here are the problems that trip people up most often:
PATH Issues
# If 'go' command not found:
echo $PATH | grep go
which go
# Fix by ensuring Go bin directory is in PATH
export PATH=$PATH:/usr/local/go/bin
Permission Problems
# If you get permission errors with GOPATH:
sudo chown -R $USER:$USER $GOPATH
chmod -R 755 $GOPATH
Module Download Issues
# If go mod download fails:
go env GOPROXY
go env GOSUMDB
# Reset module cache if corrupted
go clean -modcache
Real-World Use Cases and Examples
Here’s how this Go installation performs in actual scenarios:
Web API Server
package main
import (
"encoding/json"
"net/http"
"log"
)
type Response struct {
Message string `json:"message"`
Status string `json:"status"`
}
func healthHandler(w http.ResponseWriter, r *http.Request) {
response := Response{
Message: "Go on Ubuntu 24 is running",
Status: "healthy",
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}
func main() {
http.HandleFunc("/health", healthHandler)
log.Println("Server starting on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
System Monitoring Tool
package main
import (
"fmt"
"os"
"runtime"
"time"
)
func main() {
for {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("Timestamp: %s\n", time.Now().Format("2006-01-02 15:04:05"))
fmt.Printf("Goroutines: %d\n", runtime.NumGoroutine())
fmt.Printf("Memory: %d KB\n", m.Alloc/1024)
fmt.Printf("GC Cycles: %d\n", m.NumGC)
fmt.Println("---")
time.Sleep(5 * time.Second)
}
}
Integration with Ubuntu 24 Services
Running Go applications as systemd services is straightforward on Ubuntu 24:
# Create a systemd service file
sudo tee /etc/systemd/system/mygoapp.service << EOF
[Unit]
Description=My Go Application
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/go/src/myapp
ExecStart=/home/ubuntu/go/bin/myapp
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
# Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable mygoapp
sudo systemctl start mygoapp
# Check service status
sudo systemctl status mygoapp
Development Workflow Setup
A complete development environment includes these additional tools:
# Install useful Go tools
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/tools/cmd/godoc@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Set up a new project with modules
mkdir myproject && cd myproject
go mod init github.com/yourusername/myproject
# Create a basic project structure
mkdir -p {cmd,internal,pkg,web,scripts}
Performance Benchmarks
On a standard Ubuntu 24 setup, Go shows impressive performance characteristics:
Metric | Value | Notes |
---|---|---|
Binary startup time | <10ms | Static binaries, no runtime dependencies |
Memory overhead | ~2MB | Minimal Go runtime footprint |
Compilation speed | ~100k LOC/sec | On modern hardware with SSD |
HTTP requests/sec | ~50k | Simple handler, single core |
Security Considerations
Production Go deployments on Ubuntu 24 should follow these security practices:
# Build static binaries to avoid library dependencies
CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' .
# Use multi-stage Docker builds for minimal attack surface
# Run applications as non-root user
sudo useradd -r -s /bin/false golang-app
# Set up proper file permissions
sudo chown golang-app:golang-app /path/to/your/binary
sudo chmod 755 /path/to/your/binary
For additional resources and official documentation, visit Go's official installation guide and the Go documentation.
This setup gives you a solid foundation for Go development on Ubuntu 24, whether you're building microservices, CLI tools, or high-performance web applications. The combination of Go's efficiency and Ubuntu's stability creates an excellent platform for modern software development and deployment.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.