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
- Go to golang.org/dl
- Download the Windows installer (
.msifile) - Choose the 64-bit version (most common)
Step 2: Run the Installer
- Double-click the downloaded
.msifile - Click "Next" through the installation wizard
- Choose installation location (default is fine:
C:\Program Files\Go) - Click "Install"
- Wait for installation to complete
Step 3: Verify Installation
Open Command Prompt or PowerShell and type:
go versionYou 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
- Go to golang.org/dl
- Download the macOS installer (
.pkgfile)
Step 2: Install Go
- Double-click the downloaded
.pkgfile - Follow the installation wizard
- Click "Continue" and "Install"
- Enter your password when prompted
Step 3: Verify Installation
Open Terminal and type:
go versionYou 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.gzStep 3: Add Go to PATH
Add these lines to your ~/.bashrc or ~/.zshrc:
export PATH=$PATH:/usr/local/go/binThen reload:
source ~/.bashrcStep 4: Verify Installation
go versionSetting Up Your Workspace
After installing Go, you need to set up your workspace:
1. Create Go Workspace Directory
mkdir ~/go-workspace
cd ~/go-workspace2. 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/binAdd 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.goYou 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 goLinux with apt (Ubuntu/Debian)
sudo apt update
sudo apt install golang-goLinux with yum (CentOS/RHEL)
sudo yum install golangNote: 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 # WindowsNext Steps After Installation
- Set up your editor - VS Code with Go extension is great!
- Learn the basics - Start with variables and functions
- Practice - Write small programs to get comfortable
- 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/gofolder - Linux: Delete
/usr/local/goand remove from PATH
Next Steps
Now that Go is installed, here's what to learn next:
- Next: Learn about Go Basics - Variables, types, and basic syntax
- Explore Go Functions - Write reusable code
- Understand Go Packages - Organize your code
- Master Go Concurrency - Run multiple tasks
Happy coding with Go! 🚀