1. go
  2. /getting started
  3. /installation

How to Install Go (Golang) on Any Operating System

Go installation is straightforward across all major operating systems. This guide will walk you through the process step by step, ensuring you have a working Go development environment.

System Requirements

Before installing Go, ensure your system meets these minimum requirements:

  • Windows 7 or later (64-bit)
  • macOS 10.13 High Sierra or later
  • Linux with kernel version 2.6.23 or later
  • Disk space: 2GB for installation and dependencies
  • RAM: 1GB minimum (4GB recommended)

Installing on macOS

The simplest way to install Go on macOS is using Homebrew:

# Update Homebrew
brew update

# Install Go
brew install go

Manual Installation

  1. Download the latest package from the official Go website:
# Visit https://go.dev/dl/
# Download the .pkg installer for macOS
  1. Run the installer package:
# Double-click the downloaded .pkg file
# Follow the installation wizard

Installing on Linux

Ubuntu/Debian

# Update package list
sudo apt update

# Install Go
sudo apt install golang-go

# Verify installation
go version

Fedora/RHEL

# Install Go
sudo dnf install golang

# Verify installation
go version

Manual Installation (All Linux Distributions)

# Download the latest version
wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz

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

# Extract the archive
sudo tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz

Installing on Windows

  1. Download the Windows MSI installer from golang.org
  2. Run the MSI installer
  3. Follow the installation wizard
  4. Verify installation by opening Command Prompt:
go version

Environment Setup

Setting GOPATH and GOROOT

Add these to your shell configuration file (~/.bashrc, ~/.zshrc, etc.):

# GOROOT is the location where Go is installed
export GOROOT=/usr/local/go

# GOPATH is your workspace directory
export GOPATH=$HOME/go

# Add Go binary directory to PATH
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

For Windows, set environment variables through System Properties:

  1. Right-click on 'This PC' or 'My Computer'
  2. Click 'Properties'
  3. Click 'Advanced system settings'
  4. Click 'Environment Variables'
  5. Add or modify:
    • GOROOT: C:\Go
    • GOPATH: C:\Users\YourUsername\go
    • PATH: Add %GOROOT%\bin

Verifying Installation

Run these commands to verify your installation:

# Check Go version
go version

# View Go environment information
go env

# Create and run a test program
echo 'package main

import "fmt"

func main() {
    fmt.Println("Go installation successful!")
}' > test.go

go run test.go

IDE Setup

For the best development experience, install one of these IDEs/editors:

  1. Visual Studio Code

    • Install VS Code
    • Install Go extension
    • Install Go tools:
    go install golang.org/x/tools/gopls@latest
    
  2. GoLand

    • Download from JetBrains
    • No additional setup required
    • Built-in Go tools
  3. Vim/Neovim

    • Install vim-go plugin
    • Run :GoInstallBinaries

Common Installation Issues

Path Issues

# If 'go' command not found, check PATH
echo $PATH | grep go

# Verify binary location
which go

Permission Issues

# Fix permission issues on Linux/macOS
sudo chown -R $USER:$USER /usr/local/go
sudo chmod -R 755 /usr/local/go

Proxy Settings

If behind a corporate firewall:

# Set GOPROXY
go env -w GOPROXY=https://proxy.golang.org,direct

# If needed, set GOPRIVATE for private repositories
go env -w GOPRIVATE=*.internal.company.com

Updating Go

On macOS (Homebrew)

brew upgrade go

On Linux

# Using package manager
sudo apt upgrade golang-go  # Ubuntu/Debian
sudo dnf upgrade golang    # Fedora/RHEL

# Manual update
# Download new version and repeat installation steps

On Windows

  • Download new MSI installer
  • Run installer (automatically updates existing installation)

Next Steps

After installation:

  1. Write your first Go program
  2. Set up your Go workspace
  3. Learn about Go modules
  4. Explore Go tools

Additional Resources