Go is a fast, compiled language popular for building high-performance backend services, CLI tools, and infrastructure software (Docker and Kubernetes are both written in Go). This guide covers installing Go from the official binary distribution.
Prerequisites
- Ubuntu 22.04/24.04 or Debian 11/12 VPS
- Root or sudo access
Step 1 — Remove Any Previous Go Installation
sudo rm -rf /usr/local/go
Step 2 — Download the Latest Go Release
Check the current version at Go's official downloads page, then:
wget https://go.dev/dl/go1.23.0.linux-amd64.tar.gz
Adjust the version number and architecture (arm64 for ARM-based VPS instances) as needed.
Step 3 — Extract to /usr/local
sudo tar -C /usr/local -xzf go1.23.0.linux-amd64.tar.gz
Step 4 — Add Go to Your PATH
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc
Step 5 — Verify Installation
go version
Step 6 — Set Up a Workspace and Test
mkdir -p ~/go-projects/hello
cd ~/go-projects/hello
nano main.go
package main
import "fmt"
func main() {
fmt.Println("Hello from Go!")
}
Step 7 — Initialize a Module
go mod init hello
Step 8 — Run the Program
go run main.go
Building a Compiled Binary
go build -o hello main.go
./hello
Go compiles to a single self-contained binary with no runtime dependencies required on the deployment server — a major operational advantage.
Managing Dependencies
go get github.com/gin-gonic/gin
Running a Go Application as a systemd Service
sudo nano /etc/systemd/system/myapp.service
[Unit]
Description=My Go Application
After=network.target
[Service]
ExecStart=/opt/myapp/myapp
Restart=always
User=deploy
WorkingDirectory=/opt/myapp
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
Common Errors
"go: command not found" — the PATH export wasn't applied; verify with echo $PATH and re-source your shell profile.
Wrong architecture downloaded — confirm your VPS's architecture with uname -m before downloading (x86_64 needs the amd64 build; ARM VPS needs arm64).
Best Practices
- Deploy compiled binaries rather than running
go runin production - Use Go modules (
go.mod/go.sum) for reproducible dependency management - Run production services via systemd for automatic restart and boot persistence
Related Articles
- How to Manage Services with systemd and systemctl
- Nginx as a Reverse Proxy for Node.js/Docker Apps
- How to Install Docker Engine on Ubuntu & Debian
