
Guide: How to Install Go on Ubuntu 24
Getting Go installed on your Ubuntu 24 server is one of those fundamental tasks that’ll set you up for building everything from microservices to command-line tools. Go’s speed, simplicity, and excellent concurrency support make it a go-to choice for system administrators and developers working on cloud-native applications, DevOps tooling, and high-performance backend services. This guide walks you through multiple installation methods, covers common gotchas you’ll likely encounter, and shows you how to verify everything’s working correctly so you can start coding right away.
How Go Installation Works on Ubuntu 24
Ubuntu 24 offers several paths for installing Go, each with different trade-offs. The official Ubuntu repositories typically include an older but stable version that’s been tested with the distribution. Meanwhile, downloading directly from Google’s servers gets you the latest release with all the newest features and performance improvements.
Go’s installation process involves setting up the binary, configuring environment variables, and establishing your workspace structure. Unlike some languages that scatter files across your system, Go keeps things relatively contained with a single installation directory and clear environment variable requirements.
Method 1: Installing Go from Ubuntu Repositories
The easiest approach uses Ubuntu’s package manager. First, update your package index and install Go:
sudo apt update
sudo apt install golang-go
Check the installed version:
go version
This method typically installs Go to /usr/lib/go-1.x
and automatically sets up basic environment variables. However, Ubuntu repos often lag behind the latest Go releases by several months.
Method 2: Installing Latest Go from Official Source
For the newest features and performance improvements, download directly from Google. First, check the latest version at https://golang.org/dl/.
Remove any existing Go installation:
sudo rm -rf /usr/local/go
Download and extract the latest version (replace version number as needed):
wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz
Add Go to your PATH by editing your shell profile:
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export GOBIN=$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc
Verify the installation:
go version
go env GOPATH
Method 3: Using Snap Package Manager
Ubuntu 24 includes snap by default, offering another installation route:
sudo snap install go --classic
The --classic
flag gives Go full system access, which it needs for proper development work. Snap installations automatically handle PATH configuration and updates.
Installation Method Comparison
Method | Pros | Cons | Best For |
---|---|---|---|
APT Repository | Simple, integrated with system updates | Often outdated versions | Stable production environments |
Official Binary | Latest version, full control | Manual updates required | Development, latest features |
Snap Package | Auto-updates, sandboxed | Larger disk usage, potential permission issues | Desktop development |
Setting Up Your Go Workspace
Modern Go uses modules, but setting up a proper workspace structure helps organize projects:
mkdir -p $HOME/go/{bin,src,pkg}
mkdir -p $HOME/go/src/github.com/yourusername
Create a test project to verify everything works:
mkdir $HOME/go/src/hello
cd $HOME/go/src/hello
Create a simple Go program:
cat > main.go << 'EOF'
package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Printf("Hello from Go %s on %s/%s\n",
runtime.Version(),
runtime.GOOS,
runtime.GOARCH)
}
EOF
Run the program:
go run main.go
Build a binary:
go build -o hello
./hello
Common Installation Issues and Troubleshooting
Several issues pop up regularly during Go installation on Ubuntu 24:
- Permission denied errors: Usually caused by incorrect GOPATH permissions. Fix with
sudo chown -R $USER:$USER $GOPATH
- Command not found: PATH isn't updated. Double-check your shell profile and run
source ~/.bashrc
- Multiple Go versions: Remove conflicting installations before proceeding. Check
which go
andwhereis go
- Module download failures: Network issues or proxy settings. Configure with
go env -w GOPROXY=direct
If you're running into module-related issues, initialize a proper module:
go mod init example.com/hello
go mod tidy
Performance Considerations and Optimization
Go's performance characteristics make it particularly suitable for server environments. Here's how different installation methods affect performance:
Metric | APT Install | Official Binary | Snap Install |
---|---|---|---|
Startup Time | ~50ms | ~45ms | ~80ms |
Build Speed | Standard | Optimized | Standard |
Memory Usage | Minimal | Minimal | Higher (sandbox overhead) |
For maximum performance on your VPS or dedicated server, the official binary installation typically provides the best results.
Real-World Use Cases and Integration
Once Go is installed, you'll likely use it for various server-side tasks:
- Microservices development: Go's HTTP package and goroutines make it ideal for building scalable APIs
- DevOps tooling: Many popular tools like Docker, Kubernetes, and Terraform are written in Go
- System administration: Build custom monitoring tools, log processors, and automation scripts
- Network programming: Go excels at building proxies, load balancers, and network utilities
Here's a practical example of a simple HTTP health check server you might deploy:
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"time"
)
type HealthStatus struct {
Status string `json:"status"`
Timestamp time.Time `json:"timestamp"`
Uptime string `json:"uptime"`
}
var startTime = time.Now()
func healthHandler(w http.ResponseWriter, r *http.Request) {
uptime := time.Since(startTime)
status := HealthStatus{
Status: "healthy",
Timestamp: time.Now(),
Uptime: uptime.String(),
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(status)
}
func main() {
http.HandleFunc("/health", healthHandler)
fmt.Println("Health check server starting on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
Best Practices and Security Considerations
When setting up Go in production environments, follow these security practices:
- Use dedicated user accounts: Don't run Go applications as root
- Keep Go updated: Subscribe to security announcements at golang-announce
- Validate dependencies: Use
go mod verify
and consider tools likegovulncheck
- Set proper file permissions: Ensure GOPATH directories have appropriate access controls
Configure Go for production deployment:
go env -w CGO_ENABLED=0
go env -w GOOS=linux
go build -ldflags="-w -s" -a -installsuffix cgo -o myapp
This creates statically linked binaries that are easier to deploy and more secure.
Advanced Configuration and Multiple Versions
For development environments where you need multiple Go versions, consider using a version manager like g:
curl -sSL https://git.io/g-install | sh -s
source ~/.bashrc
g install 1.21.5
g install 1.20.12
g use 1.21.5
You can also configure Go for cross-compilation to target different platforms:
GOOS=windows GOARCH=amd64 go build -o myapp.exe
GOOS=darwin GOARCH=amd64 go build -o myapp-mac
This flexibility makes Go particularly valuable for building tools that need to run across different server architectures and operating systems in your infrastructure.

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.