Go BasicsJanuary 25, 2025

How to Install Go (Golang) - Step by Step Guide

Complete guide on installing Go programming language on Windows, macOS, and Linux. Learn how to set up your Go development environment.

Author: Sushil Kumar

golanginstallationsetupgetting-started

How to Install Go (Golang) - Step by Step Guide

Ready to start coding in Go? Great! Let me walk you through installing Go on your computer. Don't worry - it's straightforward, and I'll guide you through every step!

Prerequisites

Before installing Go, make sure you have:

  • A computer running Windows, macOS, or Linux
  • Administrator/sudo access (for installation)
  • Internet connection (to download Go)

That's it! Go doesn't need anything else.

Method 1: Installing on Windows

Step 1: Download Go

  1. Go to golang.org/dl
  2. Download the Windows installer (.msi file)
  3. Choose the 64-bit version (most common)

Step 2: Run the Installer

  1. Double-click the downloaded .msi file
  2. Click "Next" through the installation wizard
  3. Choose installation location (default is fine: C:\Program Files\Go)
  4. Click "Install"
  5. Wait for installation to complete

Step 3: Verify Installation

Open Command Prompt or PowerShell and type:

go version

You should see something like: go version go1.21.0 windows/amd64

If you see this, congratulations! Go is installed!

Method 2: Installing on macOS

Step 1: Download Go

  1. Go to golang.org/dl
  2. Download the macOS installer (.pkg file)

Step 2: Install Go

  1. Double-click the downloaded .pkg file
  2. Follow the installation wizard
  3. Click "Continue" and "Install"
  4. Enter your password when prompted

Step 3: Verify Installation

Open Terminal and type:

go version

You should see: go version go1.21.0 darwin/amd64 (or similar)

Method 3: Installing on Linux

Step 1: Download Go

Open terminal and run:

wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz

(Replace with the latest version number from golang.org/dl)

Step 2: Extract and Install

sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz

Step 3: Add Go to PATH

Add these lines to your ~/.bashrc or ~/.zshrc:

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

Then reload:

source ~/.bashrc

Step 4: Verify Installation

go version

Setting Up Your Workspace

After installing Go, you need to set up your workspace:

1. Create Go Workspace Directory

mkdir ~/go-workspace
cd ~/go-workspace

2. Set GOPATH (Optional for Go 1.11+)

For newer Go versions, you don't need GOPATH. But if you want to set it:

export GOPATH=$HOME/go-workspace
export PATH=$PATH:$GOPATH/bin

Add this to your shell profile file (~/.bashrc, ~/.zshrc, or Windows environment variables).

Your First Go Program

Let's test that everything works! Create a file called hello.go:

package main
 
import "fmt"
 
func main() {
    fmt.Println("Hello, World!")
}

Save it and run:

go run hello.go

You should see: Hello, World!

If you see this, everything is working perfectly!

Understanding Go Environment

Go uses these important directories:

Go Installation:
┌─────────────────────────────┐
│ /usr/local/go (Linux/Mac)  │
│ C:\Program Files\Go (Win) │
│                             │
│ Contains:                   │
│ - bin/ (go executable)     │
│ - src/ (standard library)  │
│ - pkg/ (compiled packages) │
└─────────────────────────────┘
 
Your Workspace:
┌─────────────────────────────┐
│ ~/go-workspace              │
│                             │
│ Contains:                   │
│ - src/ (your code)          │
│ - bin/ (compiled binaries)  │
│ - pkg/ (your packages)      │
└─────────────────────────────┘

Common Installation Issues

Issue 1: "go: command not found"

Solution: Go is not in your PATH. Add Go's bin directory to your PATH environment variable.

Issue 2: Wrong Go Version

Solution: Make sure you downloaded the correct version for your system (32-bit vs 64-bit).

Issue 3: Permission Denied (Linux/Mac)

Solution: Use sudo for installation, or install in your home directory.

Issue 4: Old Go Version

Solution: Download and install the latest version from golang.org/dl.

Using Package Managers (Alternative)

macOS with Homebrew

brew install go

Linux with apt (Ubuntu/Debian)

sudo apt update
sudo apt install golang-go

Linux with yum (CentOS/RHEL)

sudo yum install golang

Note: Package manager versions might be older. For the latest version, download from golang.org.

Verifying Your Setup

Run these commands to verify everything:

# Check Go version
go version
 
# Check Go environment
go env
 
# Check if Go is in PATH
which go  # Linux/Mac
where go  # Windows

Next Steps After Installation

  1. Set up your editor - VS Code with Go extension is great!
  2. Learn the basics - Start with variables and functions
  3. Practice - Write small programs to get comfortable
  4. Join the community - Check out golang.org and r/golang

Visual Explanation: Installation Process

Download Go Installer


┌──────────────┐
│ Run Installer│
│ (Windows/Mac)│
└──────┬───────┘


┌──────────────┐
│ Extract Files│
│ (Linux)      │
└──────┬───────┘


┌──────────────┐
│ Add to PATH  │
│ (if needed)  │
└──────┬───────┘


┌──────────────┐
│ Verify with  │
│ go version   │
└──────────────┘

Frequently Asked Questions (FAQ)

Q1: Which version of Go should I install?

A: Always install the latest stable version from golang.org/dl. As of 2025, Go 1.21+ is recommended.

Q2: Do I need to set GOPATH?

A: For Go 1.11+, you don't need GOPATH for most projects. Go modules handle dependencies automatically. But setting it doesn't hurt!

Q3: Can I have multiple Go versions?

A: Yes! You can use tools like g or gvm to manage multiple Go versions. But for beginners, one version is enough.

Q4: What's the difference between go run and go build?

A:

  • go run - Compiles and runs immediately
  • go build - Compiles to an executable file

Use go run for testing, go build for creating programs to distribute.

Q5: Where are Go programs installed?

A: Go itself installs to:

  • Windows: C:\Program Files\Go
  • macOS/Linux: /usr/local/go

Your code can be anywhere!

Q6: Do I need an IDE to write Go?

A: No! You can use any text editor. But IDEs like VS Code with Go extension make development much easier.

Q7: How do I update Go?

A: Download the new version and install it. It will replace the old version. Your code will still work (Go maintains backward compatibility).

Q8: Can I install Go without admin rights?

A: Yes! Install Go to your home directory and add it to your PATH. No admin rights needed!

Q9: What's GOROOT?

A: GOROOT is where Go is installed. Usually /usr/local/go or C:\Program Files\Go. You rarely need to set it manually.

Q10: How do I uninstall Go?

A:

  • Windows: Uninstall from Control Panel
  • macOS: Delete /usr/local/go folder
  • Linux: Delete /usr/local/go and remove from PATH

Next Steps

Now that Go is installed, here's what to learn next:

Happy coding with Go! 🚀