Skip to content

Go Installation Guide — Set Up Go on Linux macOS and Windows

DodaTech Updated 2026-06-28 6 min read

In this tutorial, you will learn about Go Installation Guide. We cover key concepts, practical examples, and best practices to help you master this topic.

Go installation requires downloading the Go distribution, setting up GOPATH environment variables, and understanding the Go modules system for dependency management.

What You'll Learn

  • Installing Go on any operating system
  • Configuring GOPATH and environment variables
  • Understanding Go modules and go.mod
  • Setting up a development environment

Why It Matters

A proper Go setup ensures fast compilation, correct module resolution, and smooth development. Docker, Kubernetes, and other Go projects rely on precise Go version management. Doda Browser uses Go for backend services and requires specific toolchain versions.

Real-World Use

Every Go developer needs a configured environment. Continuous integration pipelines install Go, set up modules, and build binaries. Cross-compilation for different platforms is a key Go feature that requires proper setup.

flowchart LR
    A["Install Go"] --> B["Download"]
    B --> C["Configure PATH"]
    C --> D["Verify"]
    D --> E["Hello World"]
    A:::current --> B
    style A fill:#2563eb,stroke:#2563eb,color:#fff
    style B fill:#dbeafe,stroke:#2563eb,color:#1e40af
    style C fill:#dbeafe,stroke:#2563eb,color:#1e40af
    style D fill:#dbeafe,stroke:#2563eb,color:#1e40af
    style E fill:#f1f5f9,stroke:#94a3b8,color:#64748b

Installing Go

Linux

# Download the latest Go tarball
wget https://go.dev/dl/go1.24.0.linux-amd64.tar.gz

# Remove previous installation and extract
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.24.0.linux-amd64.tar.gz

# Add to PATH
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc

# Verify
go version

macOS

# Using Homebrew
brew install go

# Or download from go.dev
wget https://go.dev/dl/go1.24.0.darwin-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.24.0.darwin-amd64.tar.gz

Windows

Download the MSI installer from go.dev and run it. The installer automatically sets PATH.

Verifying Installation

go version
# go version go1.24.0 linux/amd64

Setting Up Go Environment

# Set GOPATH (default: $HOME/go)
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

# Add to ~/.bashrc for permanence
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc

# Check environment
go env

Key environment variables:

  • GOROOT: Go installation directory
  • GOPATH: Workspace directory for Go code and binaries
  • GOBIN: Where compiled binaries are installed
  • GOOS/GOARCH: Target OS and architecture for cross-compilation

Go Modules

Go modules replaced the old GOPATH-based dependency system. Modules are the standard for managing dependencies.

Creating a Module

mkdir myproject
cd myproject
go mod init example.com/myproject

This creates a go.mod file:

module example.com/myproject

go 1.24

Adding Dependencies

go get github.com/gin-gonic/gin

This updates go.mod and creates go.sum:

module example.com/myproject

go 1.24

require github.com/gin-gonic/gin v1.9.1

Common Module Commands

go mod init <module>    # Initialize new module
go mod tidy             # Add missing, remove unused deps
go mod download         # Download all dependencies
go mod verify           # Verify dependencies
go list -m all          # List all dependencies

Your First Go Program

package main

import "fmt"

func main() {
    fmt.Println("Hello, Go!")
    fmt.Println("Go version:", runtime.Version())
}

Run it:

go run main.go
# Hello, Go!
# Go version: go1.24.0

Cross-Compilation

Go makes cross-compilation simple:

# Build for Linux 64-bit
GOOS=linux GOARCH=amd64 go build -o app-linux

# Build for macOS 64-bit
GOOS=darwin GOARCH=amd64 go build -o app-macos

# Build for Windows 64-bit
GOOS=windows GOARCH=amd64 go build -o app.exe

# Build for ARM (Raspberry Pi)
GOOS=linux GOARCH=arm64 go build -o app-arm

Development Tools

gofmt (Code Formatting)

gofmt -w main.go        # Format file in place
gofmt -d main.go        # Show differences only

golint and staticcheck

go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...

go vet

go vet ./...   # Report suspicious constructs

IDE Setup

VSCode

Install the Go extension. It provides:

  • IntelliSense (code completion)
  • Code navigation (go to definition)
  • Debugging support
  • gofmt on save

GoLand

JetBrains' dedicated Go IDE with built-in tools, Refactoring, and debugging.

Common Mistakes

1. Forgetting go mod init

# Wrong — no module
go run main.go  # Error: could not determine module path

# Right
go mod init example.com/app
go run main.go

2. Not Setting GOPATH/bin in PATH

export PATH=$PATH:$GOPATH/bin  # Required for 'go install' binaries

3. Ignoring go.mod and go.sum

Always commit both go.mod and go.sum to version control for reproducible builds.

4. Using GOPATH Mode for New Projects

Always use Go modules (go mod init). The old GOPATH mode is deprecated.

5. Not Using Go Version Management

Use go install to manage Go versions:

go install golang.org/dl/go1.23.0@latest
go1.23.0 download

6. Mixing Module Paths

Keep module paths unique. Don't name your module main — use a descriptive path like github.com/username/project.

Practice Questions

1. What command initializes a new Go module?

go mod init <module-path> creates a go.mod file with the module path.

2. What does GOPATH do?

GOPATH is the workspace directory where Go stores downloaded modules, compiled binaries, and package source code. Defaults to $HOME/go.

3. How do you cross-compile a Go program?

Set GOOS and GOARCH environment variables before running go build. Example: GOOS=linux GOARCH=amd64 go build.

4. What files does Go modules use for dependency management?

go.mod declares the module path and dependencies. go.sum contains cryptographic checksums to verify dependency integrity.

Challenge: Set up a Go module called github.com/yourname/tutorial, install the cobra CLI library, and verify all dependencies are listed.

Solution
mkdir tutorial && cd tutorial
go mod init github.com/yourname/tutorial
go get github.com/spf13/cobra@latest
go mod tidy
go list -m all

Expected output shows cobra and its dependencies listed.

FAQ

{{< faq question="Should I use GOPATH or Go modules?" >}} Use Go modules (existing since Go 1.11, default since Go 1.16). Modules are the standard for dependency management. GOPATH mode is deprecated. {{< /faq >}}

{{< faq question="What is the difference between go run and go build?" >}} go run compiles and runs the program without creating a binary. go build compiles and creates an executable binary in the current directory. {{< /faq >}}

{{< faq question="How do I update Go to the latest version?" >}} Download and install the latest version from go.dev. Or use go install golang.org/dl/go1.24.0@latest && go1.24.0 download for version management. {{< /faq >}}

{{< faq question="Why does go mod tidy remove my dependencies?" >}} go mod tidy removes dependencies not used by any package in your module. It also adds dependencies needed by imports in your code. Run it before committing. {{< /faq >}}

{{< faq question="Can I have multiple Go versions installed?" >}} Yes. Use go install golang.org/dl/go1.23.0@latest for each version. Each version's binary is named like go1.23.0. {{< /faq >}}

Try It Yourself

# Create and run a Go project
mkdir -p hello && cd hello
go mod init example.com/hello

cat > main.go << 'EOF'
package main

import (
    "fmt"
    "runtime"
)

func main() {
    fmt.Println("Go Environment:")
    fmt.Println("  Version:", runtime.Version())
    fmt.Println("  GOOS:", runtime.GOOS)
    fmt.Println("  GOARCH:", runtime.GOARCH)
    fmt.Println("  CPUs:", runtime.NumCPU())
}
EOF

go run main.go

Expected output:

Go Environment:
  Version: go1.24.0
  GOOS: linux
  GOARCH: amd64
  CPUs: 8

What's Next

Now that Go is installed, write your first complete Go program with package main and understanding the build Process.

Topic Description Link
Go Hello World Your first Go program {{< ref "03-hello-world" >}}
Go Variables var, :=, types, zero values {{< ref "04-variables" >}}
Python Setup Compare Python environment setup Python

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro

Home Browse Go