Go Installation Guide

Requirements

Go can run on multiple operating systems including Linux, macOS, and Windows. Different operating systems have different installation methods, but the core requirements are similar. Ensure your system meets the following basic requirements to successfully install and use the Go language development environment.

Regarding operating systems, Go supports a wide range of platforms. For Linux, Go can run on mainstream distributions like Ubuntu, Debian, Fedora, CentOS, and RHEL. macOS requires macOS 10.13 (High Sierra) or later. Windows requires Windows 10 or later, while also supporting Windows 7 and 8.1, though additional configuration may be required.

Regarding hardware, Go's requirements are relatively low. Installing Go only requires about 100MB of disk space, though actual project development may require more space depending on project size. For memory, 2GB RAM is sufficient for daily development, though more may be needed for large-scale compilation or running extensive tests.

The Go compiler itself has no special CPU requirements, and modern architectures like x86-64 and ARM64 work well. Go supports cross-compilation, allowing binaries for other platforms to be compiled on one platform.

Installation Steps

Installing on Linux

On Linux systems, using the official tarball is recommended as it's the cleanest and most flexible method. First, download the latest version tarball from the Go official website:

# Download Go (replace with latest version)
wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz

# Remove old Go installation (if exists)
sudo rm -rf /usr/local/go

# Extract to /usr/local
sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz

Next, add Go's binary directory to the PATH environment variable. Edit ~/.bashrc or ~/.profile and add the following line:

export PATH=$PATH:/usr/local/go/bin

After saving, apply the changes:

source ~/.bashrc

Or on macOS or some Linux distributions:

source ~/.profile

Installing on macOS

On macOS systems, there are two main installation methods. The first is using the Homebrew package manager, suitable for users who already have Homebrew configured:

# Install using Homebrew
brew install go

# Verify installation
go version

The second method is downloading the official macOS installer package. Visit the Go official website to download the .pkg installer, double-click to run, and follow the installation wizard. The installer automatically configures environment variables.

After installation, open Terminal and verify:

go version

You should see output like "go1.21.5 darwin/amd64".

Installing on Windows

On Windows systems, using the MSI installer is recommended. Visit the Go official website to download the Windows MSI installer, double-click to run, and follow the installation wizard. The installer automatically configures environment variables including PATH.

After installation, open Command Prompt or PowerShell and verify:

go version

Windows users can also use Chocolatey package manager:

choco install golang

For developers needing to manage multiple Go versions simultaneously, using a version manager is recommended. Common version managers include gvm (Go Version Manager) and asdf-go:

Installing and using gvm:

# Install gvm
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

# Install Go version
gvm install go1.21.5
gvm use go1.21.5 --default

asdf is a multi-language version manager that supports Go:

# Install asdf plugin
asdf plugin add golang

# Install Go version
asdf install golang 1.21.5
asdf global golang 1.21.5

Verifying Installation

After installation, verify Go is correctly installed. Open Terminal or Command Prompt and run:

# Check Go version
go version

# Check Go environment information
go env

The go env command outputs multiple environment variables including GOPATH, GOROOT, GOOS, GOARCH, etc. This information is important for understanding Go's working method and environment configuration.

Run a simple program to verify the entire development environment works correctly:

# Create working directory
mkdir -p $HOME/go/src/hello
cd $HOME/go/src/hello

# Initialize module (Go 1.16+ recommended)
go mod init hello

# Create test program
cat > main.go << 'EOF'
package main

import "fmt"

func main() {
    fmt.Println("Hello, Go!")
}
EOF

# Run program
go run main.go

If it outputs "Hello, Go!", the Go development environment is correctly configured.

Environment Configuration

GOPATH and Modules

Before Go 1.11, Go used GOPATH mode to manage dependencies. From Go 1.11, Go introduced module support, and using go mod to manage project dependencies is recommended. When using modules, there's no need to set GOPATH, and projects can be created in any directory.

For enterprise intranet environments or when using private repositories, you may need to configure the GOPRIVATE environment variable:

export GOPRIVATE=github.com/company/*

Proxy Configuration

In regions like mainland China, direct access to Go's official module repository may be slow or unavailable. You can configure Go module proxy:

# Use Alibaba Cloud proxy
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct

# Or use Qiniu Cloud proxy
go env -w GOPROXY=https://goproxy.cn,direct

IDE Configuration

Go development typically uses editors like VS Code, GoLand, or Sublime Text. VS Code requires installing the Go extension plugin to get a good development experience, including code completion, debugging, formatting, and more.

GoLand is a professional Go IDE from JetBrains that provides the most complete Go development support, including advanced debugging, refactoring, and testing features.

Upgrading and Uninstallation

Upgrading Go Version

Upgrading Go is simple. Download the new version's installer and reinstall following the steps above. The new installer will overwrite the old version.

Users of version managers can easily switch between different versions:

# gvm
gvm install go1.22.0
gvm use go1.22.0

# asdf
asdf install golang 1.22.0
asdf global golang 1.22.0

Uninstalling Go

On Linux or macOS, uninstalling Go only requires removing the installation directory:

# Remove Go installation directory
sudo rm -rf /usr/local/go

# Remove from PATH
# Edit ~/.bashrc or ~/.profile and remove related lines

On Windows, uninstall through Control Panel's Programs and Features, or use Chocolatey:

choco uninstall golang