How to Install Go (Golang) on Ubuntu 24.04 — Complete Dev Environment
Quick Summary
This guide walks you through installing Go (Golang) on Ubuntu 24.04, configuring your workspace, and building your first programs. By the end, you will have a production-ready Go development environment running on your VPS with modules, tooling, and a systemd-managed service.
Already know what you are doing? Jump straight to Method 1: Install from Official Tarball.
Table of Contents
- What is Go?
- Why Run Go on a VPS?
- Prerequisites
- Method 1: Install from Official Tarball (Recommended)
- Method 2: Install via apt (Older Version)
- Method 3: Install via Snap
- Set Up Your Go Workspace
- Write Your First Go Program
- Build a Simple HTTP Server
- Essential Go Tools
- Set Up VS Code Remote Development (Optional)
- Managing Multiple Go Versions
- Deploy a Go Application as a Service
- Cross-Compilation
- Troubleshooting
- FAQ
- Next Steps
What is Go?
Go (also called Golang) is an open-source programming language created at Google by Robert Griesemer, Rob Pike, and Ken Thompson. Released in 2009, Go was built to solve the problems engineers hit at scale: slow compilation, tangled dependencies, and difficulty writing concurrent programs.
Go compiles directly to machine code -- your programs start instantly and run fast without a virtual machine or interpreter. A compiled Go binary is a single, self-contained executable with zero runtime dependencies. You copy one file to your server and it runs.
The language is intentionally simple: roughly 25 keywords, a strict formatter that eliminates style debates, and a standard library covering HTTP servers, cryptography, JSON, and more. Concurrency is a first-class feature through goroutines (lightweight threads) and channels, making Go ideal for network services that handle thousands of simultaneous connections.
Some of the most important infrastructure projects in the world are written in Go:
- Docker -- the container runtime
- Kubernetes -- container orchestration at planetary scale
- Terraform -- infrastructure as code
- Hugo -- the fastest static site generator
- Prometheus -- monitoring and alerting
- Caddy -- automatic HTTPS web server
Why Run Go on a VPS?
A VPS gives you a complete development and deployment environment on a single machine. Go is particularly well-suited to this workflow:
- Build and deploy in the same place. Write code, compile it, and run it without transferring files between machines.
- Minimal resource consumption. A Go binary uses 5-20 MB of RAM at idle, compared to 50-100 MB for Node.js or 200+ MB for Java. On 8 GB of RAM you can run dozens of Go services.
- No runtime dependencies. Deployment means copying a single binary. No runtime to install, no package versions to manage, no virtual environments.
- Perfect for microservices and APIs. Go's built-in HTTP server, fast startup, and small memory footprint are ideal for microservice architectures.
- CI/CD on the same box. Go compiles so fast that your VPS doubles as a build server -- build, test, and deploy in seconds.
- CLI tools and automation. Go excels at server-side command-line tools: log parsers, backup scripts, monitoring agents, and deployment automation.
Prerequisites
Before you begin, make sure you have the following:
- A VPS running Ubuntu 24.04 LTS. The CloudCore Starter plan (4 vCPU, 8 GB RAM, 75 GB NVMe) provides more than enough resources for Go development and deployment.
- SSH access to your server with a user that has
sudoprivileges. - Basic familiarity with the Linux command line.
ssh your-user@your-server-ipUpdate your system packages before proceeding:
sudo apt update && sudo apt upgrade -yMethod 1: Install from Official Tarball (Recommended)
The recommended method. You get the latest stable release and full version control.
Step 1: Download the Latest Go Release
The latest stable release is Go 1.24.2. Check the official downloads page for newer versions.
cd /tmp
curl -OL https://go.dev/dl/go1.24.2.linux-amd64.tar.gzVerify the download integrity by checking the SHA256 checksum against the value listed on the downloads page:
sha256sum go1.24.2.linux-amd64.tar.gzStep 2: Remove Any Previous Installation
sudo rm -rf /usr/local/goStep 3: Extract to /usr/local
sudo tar -C /usr/local -xzf go1.24.2.linux-amd64.tar.gzStep 4: Set Up Your PATH
Add Go's binary directory to your PATH. Open your shell profile:
nano ~/.profileAdd the following lines at the end of the file:
# Go environment
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$HOME/go/binThe first line makes the go command available. The second line ensures that Go binaries you install with go install are also in your PATH.
Load the updated profile:
source ~/.profileTip: If you usebashas your shell, you can also add these lines to~/.bashrcinstead. Forzsh, use~/.zshrc. The~/.profilefile works for all POSIX-compatible shells.
Step 5: Verify the Installation
Confirm that Go is installed correctly:
go versionExpected output:
go version go1.24.2 linux/amd64Check that the environment is configured properly:
go env GOPATH GOROOTExpected output:
/home/your-user/go
/usr/local/goGo is now installed and ready to use.
Method 2: Install via apt (Older Version)
Ubuntu's repositories include Go, but the version typically lags behind the latest stable.
sudo apt update
sudo apt install -y golang-go
go versionNote: Ubuntu 24.04 provides Go 1.22.x via apt. For the latest version, use Method 1. To switch later, first remove the apt version: sudo apt remove -y golang-go golang-src.Method 3: Install via Snap
sudo snap install go --classic
go versionThe --classic flag gives Go full system access for compilation. The snap version may lag slightly behind the official release.
Set Up Your Go Workspace
Understanding GOPATH
The GOPATH environment variable defines your Go workspace. By default, it is set to ~/go. This directory is where Go stores downloaded modules, compiled binaries, and build cache.
echo $GOPATHIf this is empty or not set, Go uses the default ~/go. Create the workspace directories:
mkdir -p ~/go/{bin,src,pkg}Here is what each directory is for:
| Directory | Purpose |
|---|---|
~/go/bin | Compiled binaries from go install |
~/go/src | Source code (legacy GOPATH mode) |
~/go/pkg | Cached compiled packages |
Go Modules: The Modern Way
Since Go 1.16, Go modules are the standard dependency manager. You can create projects anywhere -- no need to work inside GOPATH/src.
Create a project and initialize a module:
mkdir -p ~/projects/myapp
cd ~/projects/myapp
go mod init github.com/your-username/myappThis creates a go.mod file tracking your module path and dependencies. When you import external packages, Go automatically downloads them and pins exact versions in go.mod and go.sum.
Write Your First Go Program
Create a main.go file in your project directory:
nano ~/projects/myapp/main.goWrite the classic "Hello, World" program:
package mainimport "fmt"
func main() { fmt.Println("Hello from Go on Ubuntu 24.04!") }
The main package defines a standalone executable, and main() is the entry point. Run it directly:
cd ~/projects/myapp
go run main.goOutput:
Hello from Go on Ubuntu 24.04!Now compile it into a binary:
go build -o myapp main.goThis produces a myapp executable in the current directory. Run it:
./myappOutput:
Hello from Go on Ubuntu 24.04!Check the binary size:
ls -lh myappYou will see the binary is around 1.8 MB -- a self-contained executable with no external dependencies.
Build a Simple HTTP Server
Go's standard library includes a production-quality HTTP server -- no external framework needed. Create a new project:
mkdir -p ~/projects/webserver
cd ~/projects/webserver
go mod init github.com/your-username/webserver
nano main.goWrite the server code:
package mainimport ( "encoding/json" "fmt" "log" "net/http" "time" )
type HealthResponse struct { Status string
json:"status"Timestamp stringjson:"timestamp"Version stringjson:"version"}func homeHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Welcome to my Go web server running on Ubuntu 24.04!\n") }
func healthHandler(w http.ResponseWriter, r *http.Request) { resp := HealthResponse{ Status: "healthy", Timestamp: time.Now().UTC().Format(time.RFC3339), Version: "1.0.0", } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(resp) }
func main() { http.HandleFunc("/", homeHandler) http.HandleFunc("/health", healthHandler)
port := ":8080" log.Printf("Server starting on port %s", port) if err := http.ListenAndServe(port, nil); err != nil { log.Fatalf("Server failed to start: %v", err) } }
Build and run:
go build -o webserver main.go
./webserverIn a separate terminal (or using curl on the same server), test the endpoints:
curl http://localhost:8080/Output:
Welcome to my Go web server running on Ubuntu 24.04!curl http://localhost:8080/healthOutput:
{"status":"healthy","timestamp":"2026-04-16T12:00:00Z","version":"1.0.0"}Press Ctrl+C to stop the server. We will turn this into a systemd service later in the guide.
Essential Go Tools
Go ships with powerful built-in tools. Here are the ones you will use daily.
go fmt -- enforces Go's canonical formatting style:
go fmt ./...go vet -- catches common mistakes the compiler misses (bad format strings, unreachable code, etc.):
go vet ./...go test -- runs tests in any file ending with _test.go:
go test ./... # standard output
go test -v ./... # verbose, shows individual test namesgo mod tidy -- adds missing and removes unused dependencies:
go mod tidygolangci-lint -- a fast linter aggregator that runs dozens of checks in parallel. Install it:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.0Run it against your project:
golangci-lint run ./...Set Up VS Code Remote Development (Optional)
VS Code with the Remote SSH extension lets you develop directly on your VPS with full IDE features.
Ctrl+Shift+P (or Cmd+Shift+P on macOS), select Remote-SSH: Connect to Host, and enter your-user@your-server-ip.Ctrl+Shift+X), search for "Go", and install the official extension (golang.Go).gopls, dlv, staticcheck, and other Go tools on the remote.You now have IntelliSense, code navigation, debugging, and an integrated terminal -- all running on your VPS with no sync delays.
Add these recommended settings (Ctrl+,):
{
"go.formatTool": "goimports",
"go.lintTool": "golangci-lint",
"editor.formatOnSave": true,
"[go]": {
"editor.defaultFormatter": "golang.go",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}Managing Multiple Go Versions
Sometimes you need to test against different Go versions, or a project requires a specific version. Go has a built-in mechanism for this.
Install an Additional Go Version
Use go install to download and install a specific version:
go install golang.org/dl/go1.22.8@latest
go1.22.8 downloadThis installs Go 1.22.8 alongside your primary installation. Use it by calling the versioned binary:
go1.22.8 versionOutput:
go version go1.22.8 linux/amd64Build with the specific version:
go1.22.8 build -o myapp main.goList Installed Versions
Check which versioned Go installations you have:
ls ~/sdk/Each version is stored in ~/sdk/go1.XX.X/.
Switch Your Default Version
To make a different version your default, update the tarball installation. Download and extract the desired version following Method 1, which replaces /usr/local/go.
Deploy a Go Application as a Service
For production, you want your application to start on boot, restart on failure, and log to the journal. Systemd handles all of this.
Step 1: Build Your Binary
Compile with optimizations:
cd ~/projects/webserver
CGO_ENABLED=0 go build -ldflags="-s -w" -o webserver main.goCGO_ENABLED=0 produces a fully static binary. -ldflags="-s -w" strips debug symbols, reducing binary size by 20-30%. Copy the binary to a standard location:
sudo cp webserver /usr/local/bin/webserverStep 2: Create a Systemd Unit File
Create a dedicated system user for the service:
sudo useradd --system --no-create-home --shell /usr/sbin/nologin goappCreate the service file:
sudo nano /etc/systemd/system/webserver.service[Unit] Description=Go Web Server After=network.target[Service] Type=simple User=goapp Group=goapp ExecStart=/usr/local/bin/webserver Restart=on-failure RestartSec=5 StandardOutput=journal StandardError=journal
Security hardening
NoNewPrivileges=true ProtectSystem=strict ProtectHome=true ReadWritePaths=/var/logEnvironment variables (if needed)
Environment=PORT=8080
Environment=DB_HOST=localhost
[Install] WantedBy=multi-user.target
Step 3: Enable and Start the Service
sudo systemctl daemon-reload
sudo systemctl enable webserver
sudo systemctl start webserver
sudo systemctl status webserverView logs in real time (press Ctrl+C to stop):
sudo journalctl -u webserver -fVerify:
curl http://localhost:8080/healthYour Go application now starts on boot and restarts automatically on failure.
Cross-Compilation
Go can build binaries for any supported OS and architecture from a single machine. Set the GOOS and GOARCH environment variables before building:
# Linux 64-bit (most common VPS target)
GOOS=linux GOARCH=amd64 go build -o myapp-linux-amd64 main.gomacOS Apple Silicon
GOOS=darwin GOARCH=arm64 go build -o myapp-darwin-arm64 main.goWindows 64-bit
GOOS=windows GOARCH=amd64 go build -o myapp-windows-amd64.exe main.goLinux ARM (Raspberry Pi, ARM VPS)
GOOS=linux GOARCH=arm64 go build -o myapp-linux-arm64 main.goList all supported platform combinations:
go tool dist listA common workflow is to develop on your local machine and cross-compile for your Linux VPS, then deploy with scp:
GOOS=linux GOARCH=amd64 go build -o myapp main.go
scp myapp your-user@your-server-ip:/usr/local/bin/
ssh your-user@your-server-ip sudo systemctl restart webserverTroubleshooting
"go: command not found"
Your PATH does not include Go's binary directory. Verify that /usr/local/go/bin is in your PATH:
echo $PATHIf it is missing, add it to your shell profile and reload:
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
source ~/.profileIf you installed via snap, ensure /snap/bin is in your PATH.
"cannot find module providing package..."
You need to initialize a Go module in your project directory:
cd /path/to/your/project
go mod init your-module-name
go mod tidyIf you already have a go.mod file, run go mod tidy to resolve missing dependencies.
"permission denied" Errors
Check ownership of the Go installation directory:
ls -la /usr/local/goThe directory should be owned by root. If not, fix it:
sudo chown -R root:root /usr/local/goFor your GOPATH directory, ensure it is owned by your user:
sudo chown -R $USER:$USER ~/goBuild Fails with "cgo: C compiler not found"
Install a C compiler if your project uses cgo, or disable cgo entirely:
sudo apt install -y build-essential # if you need cgo
CGO_ENABLED=0 go build -o myapp . # if you don'tFAQ
Go vs Rust: Which Should I Choose?
Go prioritizes simplicity, fast compilation, and developer productivity. Rust prioritizes memory safety and zero-cost abstractions with a steeper learning curve. Choose Go for web services, APIs, and DevOps tools where development speed matters. Choose Rust for systems programming and performance-critical code requiring fine-grained memory control. Many teams use both.
Should I Use apt or the Official Tarball?
Use the official tarball. The apt version lags behind by one or more minor releases. The tarball gives you the exact version from the Go team with immediate access to security patches. It is what the Go project itself recommends.
What IDE Should I Use for Go Development?
VS Code + Go extension is the most popular and works well over Remote SSH. GoLand (JetBrains) offers deeper refactoring and debugging. Neovim + gopls is the choice for terminal-native developers. All three use the same gopls language server under the hood.
How Do I Update Go to a Newer Version?
Download the new tarball, remove /usr/local/go, and extract. Your workspace in ~/go is unaffected:
cd /tmp
curl -OL https://go.dev/dl/go1.XX.X.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.XX.X.linux-amd64.tar.gz
go versionCan I Run Go on an ARM-Based VPS?
Yes. Download the linux-arm64 tarball instead of linux-amd64:
curl -OL https://go.dev/dl/go1.24.2.linux-arm64.tar.gz
sudo tar -C /usr/local -xzf go1.24.2.linux-arm64.tar.gzEverything else in this guide works identically. You can also cross-compile ARM binaries on x86 with GOARCH=arm64.
Next Steps
With a fully configured Go environment, here are natural next projects:
- Build a REST API with Gin or Echo. These lightweight frameworks add routing, middleware, and request binding on top of the standard library. Install Gin with
go get -u github.com/gin-gonic/gin. - Containerize with Docker. Go's static binaries are perfect for multi-stage Docker builds. Use
scratchordistrolessas the final stage to produce images under 10 MB. - Set up CI/CD with Gitea. Self-hosted Git repositories plus Gitea Actions give you automatic build, test, and deploy on every push.
- Explore the standard library. The
net/http,encoding/json,database/sql,crypto, andtestingpackages cover most needs without external dependencies. - Learn concurrency patterns. Study goroutine fan-out/fan-in, worker pools, and context-based cancellation to build scalable services.
Build Go Apps on Reliable Infrastructure
Go's efficiency shines on quality hardware. The CloudCore Starter plan gives you 4 vCPU, 8 GB RAM, and 75 GB NVMe storage -- more than enough to compile, test, and run multiple Go services simultaneously.
Every VPS-Server.host plan includes:
- Full root access with your choice of OS
- DDoS protection and a 1 Gbps network port
- 99.9% uptime SLA
- 24/7 technical support