2.2 Installing Go

There are several ways to install Go depending on your operating system and preferences. We'll cover the most common methods.

Installation on macOS

Method 1: Official Installer (Recommended)

  1. Visit the official Go website: https://go.dev/dl/
  2. Download the macOS installer (.pkg file) for the latest version
  3. Double-click the downloaded .pkg file
  4. Follow the installation wizard
  5. The installer will place Go in /usr/local/go and add it to your PATH

Method 2: Using Homebrew

If you have Homebrew installed, you can install Go with a single command:

brew install go

Method 3: Using MacPorts

If you use MacPorts:

sudo port install go

Verification after installation

After installation, open a new terminal window and verify:

go version

You should see output like: go version go1.23.x darwin/amd64 (or darwin/arm64 for Apple Silicon).

Installation on Linux

Method 1: Package Manager (Recommended for most distributions)

Ubuntu/Debian

sudo apt update
sudo apt install golang-go

Fedora

sudo dnf install golang

CentOS/RHEL

sudo yum install golang

Arch Linux

sudo pacman -S go

Method 2: Official Binary Distribution

For the latest version or if your distribution's package manager has an outdated version:

  1. Visit https://go.dev/dl/
  2. Download the Linux tarball (.tar.gz file)
  3. Remove any existing Go installation:
    sudo rm -rf /usr/local/go
  4. Extract the archive:
    sudo tar -C /usr/local -xzf go1.23.x.linux-amd64.tar.gz
  5. Add Go to your PATH by adding this line to ~/.bashrc or ~/.profile:
    export PATH=$PATH:/usr/local/go/bin
  6. Reload your shell configuration:
    source ~/.bashrc

Method 3: Snap Package

sudo snap install go --classic

Installation on Windows

Method 1: Official Installer (Recommended)

  1. Visit https://go.dev/dl/
  2. Download the Windows installer (.msi file)
  3. Double-click the downloaded .msi file
  4. Follow the installation wizard
  5. The installer will automatically add Go to your system PATH

Method 2: Manual Installation

  1. Download the Windows zip archive from https://go.dev/dl/
  2. Extract the zip file to a location like C:\Program Files\Go
  3. Add C:\Program Files\Go\bin to your system PATH:
    • Open System Properties → Environment Variables
    • Edit the Path variable in System Variables
    • Add C:\Program Files\Go\bin

Verification

Open Command Prompt or PowerShell and run:

go version

You should see: go version go1.23.x windows/amd64

Installation from Source

Building Go from source is useful if you want the latest development version or need to customize the build:

Prerequisites

Steps

# Clone the Go repository
git clone https://go.googlesource.com/go
cd go

# Checkout the desired version (e.g., go1.23)
git checkout go1.23

# Build Go (this will take several minutes)
cd src
./make.bash  # On Unix-like systems
# or
./make.bat   # On Windows

The built Go will be in the bin directory. You'll need to add it to your PATH.

Using Version Managers

Version managers allow you to easily switch between different Go versions, which is useful for testing or working on projects that require specific versions.

g (Simple Go Version Manager)

Installation:

# Install g
curl -sSL https://git.io/g-install | sh -s

# Or using Homebrew on macOS
brew install g

Usage:

# Install a specific version
g install 1.23.0

# List installed versions
g list

# Switch to a version
g 1.23.0

# Show current version
g version

gvm (Go Version Manager)

Installation:

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

Usage:

# Install a version
gvm install go1.23

# Use a version
gvm use go1.23 --default

# List versions
gvm list