Installing Go
Step-by-step guide to installing Go on various operating systems
Introduction
Go (or Golang) is a modern programming language developed at Google. Before you can start working with Go, you need to install the compiler and set up your environment. In this lesson, we’ll cover installing Go on Windows, macOS, and Linux.
Checking the Current Version
If Go is already installed on your system, you can check the version with:
go versionThe output will look something like:
go version go1.23.4 linux/amd64Installing on Windows
Option 1: Official Installer
- Head to the official site go.dev/dl
- Download the MSI installer for Windows (e.g.,
go1.23.4.windows-amd64.msi) - Run the installer and follow the prompts
- By default, Go installs to
C:\Go
Option 2: Via winget
winget install GoLang.GoOption 3: Via Chocolatey
choco install golangAfter installation, open a new terminal and verify:
go versionInstalling on macOS
Option 1: Official Installer
- Download the PKG file from go.dev/dl
- Open the downloaded file and follow the prompts
- Go will be installed to
/usr/local/go
Option 2: Via Homebrew (recommended)
brew install goVerify the installation:
go versionInstalling on Linux
Ubuntu/Debian
# Remove old version (if present)sudo rm -rf /usr/local/go
# Download and extractwget https://go.dev/dl/go1.23.4.linux-amd64.tar.gzsudo tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz
# Add to PATH (in ~/.bashrc or ~/.zshrc)echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrcsource ~/.bashrcFedora/RHEL
sudo dnf install golangArch Linux
sudo pacman -S goSetting Up Environment Variables
After installation, Go automatically configures the main variables. You can check them with:
go envKey variables:
| Variable | Description | Example Value |
|---|---|---|
GOROOT | Path to Go installation | /usr/local/go |
GOPATH | Working directory | ~/go |
GOBIN | Path for binaries | ~/go/bin |
First Programme
Let’s create a simple programme to verify the installation:
package main
import ( "fmt" "runtime")
func main() { fmt.Println("Go installed successfully!") fmt.Printf("Version: %s\n", runtime.Version())}Save the code to a file called hello.go and run it:
go run hello.goOutput (version depends on what’s installed):
Go installed successfully!Version: go1.23.4Updating Go
Windows and macOS
Simply download and run the new installer — it will replace the previous version.
Linux
# Remove old versionsudo rm -rf /usr/local/go
# Install the new one (replace with the current version)wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gzsudo tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gzManaging Versions with gvm
To work with multiple Go versions, you can use Go Version Manager:
# Install gvmbash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
# Usagegvm install go1.23.4gvm use go1.23.4 --defaultExercises
Exercise 1
Install Go on your system and run go version. What version is installed?
Exercise 2
Run go env and find the values of GOROOT and GOPATH.
Exercise 3
Create a file called check.go with the following contents and run it:
package main
import ( "fmt" "runtime")
func main() { fmt.Printf("OS: %s\n", runtime.GOOS) fmt.Printf("Arch: %s\n", runtime.GOARCH) fmt.Printf("Go version: %s\n", runtime.Version()) fmt.Printf("Num CPU: %d\n", runtime.NumCPU())}Summary
- Go can be installed via the official installer, a package manager, or manually
- After installation,
go versionshows the current version go envdisplays all Go environment variables- For working with multiple versions, use gvm
- Updating Go is done by simply reinstalling
In the next lesson, we’ll write our first programme.