Docs / Programming & Development / Setting Up a Go Development Environment on Linux

Setting Up a Go Development Environment on Linux

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 196 views · 2 min read

Install Go

wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz

Add to ~/.bashrc:

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
source ~/.bashrc
go version

Create a Project

mkdir myapp && cd myapp
go mod init github.com/yourname/myapp

Write a Simple Web Server

Create main.go:

package main

import (
    "fmt"
    "log"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello from Go!")
    })

    http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
        w.WriteHeader(http.StatusOK)
        fmt.Fprintf(w, "OK")
    })

    log.Println("Server starting on :8080")
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Build and Run

# Run directly
go run main.go

# Build a binary
go build -o myapp .
./myapp

# Cross-compile for different OS/arch
GOOS=linux GOARCH=amd64 go build -o myapp-linux .
GOOS=darwin GOARCH=arm64 go build -o myapp-mac .

Dependency Management

# Add a dependency
go get github.com/gin-gonic/gin

# Tidy dependencies
go mod tidy

# Vendor dependencies
go mod vendor

Running as a Service

Create /etc/systemd/system/myapp.service:

[Unit]
Description=My Go App
After=network.target

[Service]
Type=simple
User=www-data
ExecStart=/opt/myapp/myapp
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Was this article helpful?