Skip to main contentSkip to navigation
[email protected]
Client AreaSupport
Hosting Mammoth
HostingMammothYour Data, Our Responsibility
Home
Solutions
Hosting Services
Store
Pricing
About
Blog
API
Contact

Stay Ahead of the Curve

Get the latest insights on cybersecurity, AI innovations, and enterprise data solutions delivered to your inbox.

Hosting Mammoth
HostingMammothEnterprise Solutions

Enterprise-grade data solutions. Hosting, recovery, cybersecurity, and AI-powered services for businesses worldwide.

[email protected]
Sun - Fri, 9:00am - 5:00pm

Services

  • Cloud Hosting
  • Data Recovery
  • Cybersecurity
  • Legal Support
  • MSP Services
  • Web Development
  • AI Services
  • Free Server Migration

Hosting

  • VPS Hosting (NVMe SSD)
  • VDS Hosting (NVMe)
  • Storage VPS (High SSD)
  • GPU Servers
  • Managed Services
  • Cloud Firewall
  • Load Balancer
  • One-Click Apps
  • n8n Hosting
  • Object Storage
  • FAQ

Company

  • Store
  • Pricing
  • About Us
  • Locations
  • Blog
  • Testimonials
  • Contact
  • Affiliate Program
  • White-Label
  • Terms of Service
  • Privacy Policy
  • Browser Cookies
  • SLA

Support

  • Client Area
  • Submit Ticket
  • Knowledge Base
  • Server Status
  • API Documentation

© 2026 Hosting Mammoth. All rights reserved.

Knowledge Base
Getting StartedAccount ManagementVPS HostingGPU ServersStorage VPSCloud FirewallLoad BalancerServer ManagementBilling & PaymentsSupport & TicketsAffiliate ProgramReseller ProgramMarketplace & Appsn8n HostingManaged ServicesServer MigrationAPI & DevelopersSecurityTroubleshootingGlossaryInstall Guides
  1. Home
  2. /
  3. Support
  4. /
  5. Install Guides
  6. /
  7. How To Install Go Ubuntu
GUIDEInstall Guides

How to Install Go (Golang) on Ubuntu 24.04 — Complete Dev Environment

15 min read

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
Whether you are building microservices, CLI tools, DevOps automation, or high-performance APIs, Go is an excellent choice.

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 sudo privileges.
  • Basic familiarity with the Linux command line.
Connect to your VPS over SSH:

bash
ssh your-user@your-server-ip

Update your system packages before proceeding:

bash
sudo apt update && sudo apt upgrade -y

Method 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.

bash
cd /tmp
curl -OL https://go.dev/dl/go1.24.2.linux-amd64.tar.gz

Verify the download integrity by checking the SHA256 checksum against the value listed on the downloads page:

bash
sha256sum go1.24.2.linux-amd64.tar.gz

Step 2: Remove Any Previous Installation

bash
sudo rm -rf /usr/local/go

Step 3: Extract to /usr/local

bash
sudo tar -C /usr/local -xzf go1.24.2.linux-amd64.tar.gz

Step 4: Set Up Your PATH

Add Go's binary directory to your PATH. Open your shell profile:

bash
nano ~/.profile

Add the following lines at the end of the file:

bash
# Go environment
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$HOME/go/bin

The 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:

bash
source ~/.profile
Tip: If you use bash as your shell, you can also add these lines to ~/.bashrc instead. For zsh, use ~/.zshrc. The ~/.profile file works for all POSIX-compatible shells.

Step 5: Verify the Installation

Confirm that Go is installed correctly:

bash
go version

Expected output:

text
go version go1.24.2 linux/amd64

Check that the environment is configured properly:

bash
go env GOPATH GOROOT

Expected output:

text
/home/your-user/go
/usr/local/go

Go 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.

bash
sudo apt update
sudo apt install -y golang-go
go version
Note: 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

bash
sudo snap install go --classic
go version

The --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.

bash
echo $GOPATH

If this is empty or not set, Go uses the default ~/go. Create the workspace directories:

bash
mkdir -p ~/go/{bin,src,pkg}

Here is what each directory is for:

DirectoryPurpose
~/go/binCompiled binaries from go install
~/go/srcSource code (legacy GOPATH mode)
~/go/pkgCached 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:

bash
mkdir -p ~/projects/myapp
cd ~/projects/myapp
go mod init github.com/your-username/myapp

This 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:

bash
nano ~/projects/myapp/main.go

Write the classic "Hello, World" program:

go
package main

import "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:

bash
cd ~/projects/myapp
go run main.go

Output:

text
Hello from Go on Ubuntu 24.04!

Now compile it into a binary:

bash
go build -o myapp main.go

This produces a myapp executable in the current directory. Run it:

bash
./myapp

Output:

text
Hello from Go on Ubuntu 24.04!

Check the binary size:

bash
ls -lh myapp

You 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:

bash
mkdir -p ~/projects/webserver
cd ~/projects/webserver
go mod init github.com/your-username/webserver
nano main.go

Write the server code:

go
package main

import ( "encoding/json" "fmt" "log" "net/http" "time" )

type HealthResponse struct { Status string json:"status" Timestamp string json:"timestamp" Version string json:"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:

bash
go build -o webserver main.go
./webserver

In a separate terminal (or using curl on the same server), test the endpoints:

bash
curl http://localhost:8080/

Output:

text
Welcome to my Go web server running on Ubuntu 24.04!
bash
curl http://localhost:8080/health

Output:

json
{"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:

bash
go fmt ./...

go vet -- catches common mistakes the compiler misses (bad format strings, unreachable code, etc.):

bash
go vet ./...

go test -- runs tests in any file ending with _test.go:

bash
go test ./...        # standard output
go test -v ./...     # verbose, shows individual test names

go mod tidy -- adds missing and removes unused dependencies:

bash
go mod tidy

golangci-lint -- a fast linter aggregator that runs dozens of checks in parallel. Install it:

bash
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.0

Run it against your project:

bash
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.

  • Install VS Code and the Remote - SSH extension on your local machine.
  • Press Ctrl+Shift+P (or Cmd+Shift+P on macOS), select Remote-SSH: Connect to Host, and enter your-user@your-server-ip.
  • Once connected, open the Extensions panel (Ctrl+Shift+X), search for "Go", and install the official extension (golang.Go).
  • When prompted, click Install All to install 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+,):

    json
    {
      "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:

    bash
    go install golang.org/dl/go1.22.8@latest
    go1.22.8 download

    This installs Go 1.22.8 alongside your primary installation. Use it by calling the versioned binary:

    bash
    go1.22.8 version

    Output:

    text
    go version go1.22.8 linux/amd64

    Build with the specific version:

    bash
    go1.22.8 build -o myapp main.go

    List Installed Versions

    Check which versioned Go installations you have:

    bash
    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:

    bash
    cd ~/projects/webserver
    CGO_ENABLED=0 go build -ldflags="-s -w" -o webserver main.go

    CGO_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:

    bash
    sudo cp webserver /usr/local/bin/webserver

    Step 2: Create a Systemd Unit File

    Create a dedicated system user for the service:

    bash
    sudo useradd --system --no-create-home --shell /usr/sbin/nologin goapp

    Create the service file:

    bash
    sudo nano /etc/systemd/system/webserver.service
    ini
    [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/log

    Environment variables (if needed)

    Environment=PORT=8080

    Environment=DB_HOST=localhost

    [Install] WantedBy=multi-user.target

    Step 3: Enable and Start the Service

    bash
    sudo systemctl daemon-reload
    sudo systemctl enable webserver
    sudo systemctl start webserver
    sudo systemctl status webserver

    View logs in real time (press Ctrl+C to stop):

    bash
    sudo journalctl -u webserver -f

    Verify:

    bash
    curl http://localhost:8080/health

    Your 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:

    bash
    # Linux 64-bit (most common VPS target)
    GOOS=linux GOARCH=amd64 go build -o myapp-linux-amd64 main.go

    macOS Apple Silicon

    GOOS=darwin GOARCH=arm64 go build -o myapp-darwin-arm64 main.go

    Windows 64-bit

    GOOS=windows GOARCH=amd64 go build -o myapp-windows-amd64.exe main.go

    Linux ARM (Raspberry Pi, ARM VPS)

    GOOS=linux GOARCH=arm64 go build -o myapp-linux-arm64 main.go

    List all supported platform combinations:

    bash
    go tool dist list

    A common workflow is to develop on your local machine and cross-compile for your Linux VPS, then deploy with scp:

    bash
    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 webserver

    Troubleshooting

    "go: command not found"

    Your PATH does not include Go's binary directory. Verify that /usr/local/go/bin is in your PATH:

    bash
    echo $PATH

    If it is missing, add it to your shell profile and reload:

    bash
    echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
    source ~/.profile

    If 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:

    bash
    cd /path/to/your/project
    go mod init your-module-name
    go mod tidy

    If 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:

    bash
    ls -la /usr/local/go

    The directory should be owned by root. If not, fix it:

    bash
    sudo chown -R root:root /usr/local/go

    For your GOPATH directory, ensure it is owned by your user:

    bash
    sudo chown -R $USER:$USER ~/go

    Build Fails with "cgo: C compiler not found"

    Install a C compiler if your project uses cgo, or disable cgo entirely:

    bash
    sudo apt install -y build-essential   # if you need cgo
    CGO_ENABLED=0 go build -o myapp .     # if you don't

    FAQ

    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:

    bash
    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 version

    Can I Run Go on an ARM-Based VPS?

    Yes. Download the linux-arm64 tarball instead of linux-amd64:

    bash
    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.gz

    Everything 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 scratch or distroless as 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, and testing packages 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
    Deploy your Go environment today and start building.

    Was this article helpful?

    ← Back to Install GuidesBrowse all categories →

    Still have questions?

    Contact Support →Submit a Ticket