This guide walks you through installing the Go programming language (also called Golang) on Windows, macOS, and Linux, and then configuring your environment so you can start writing and running Go programs right away. You’ll download the official installer, set up your workspace, and verify everything works with a simple test program.
What You’ll Need
- A computer running Windows 10/11 (64-bit), macOS 11 or later, or a modern Linux distribution (Ubuntu, Debian, Fedora, etc.)
- Administrator or sudo access to install system software
- An internet connection to download the Go toolchain
- A text editor or IDE (VS Code, GoLand, or even Notepad) — optional but recommended
Step-by-Step
- Download the Go installer — Go to the official Go download page (golang.org/dl) and grab the installer for your operating system. For Windows, choose the .msi file; for macOS, the .pkg file (or the tar.gz for manual install); for Linux, the tar.gz archive.
- Install Go on Windows — Double-click the .msi file and follow the prompts. The default install location is
C:\Go. The installer automatically sets thePATHenvironment variable, so you don’t need to do it manually. After installation, close and reopen any open command prompts to pick up the new PATH. - Install Go on macOS — Open the .pkg file and follow the installer steps. It installs to
/usr/local/goand adds Go to your PATH automatically. If you prefer Homebrew, runbrew install goin Terminal — that also sets everything up. - Install Go on Linux — Remove any previous Go installation (e.g.,
rm -rf /usr/local/goif it exists), then extract the tar.gz:sudo tar -C /usr/local -xzf go1.22.4.linux-amd64.tar.gz(replace the filename with the one you downloaded). Add Go to your PATH by editing~/.profileor~/.bashrc: add the lineexport PATH=$PATH:/usr/local/go/bin, then runsource ~/.profile. - Verify the installation — Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and run
go version. You should see output likego version go1.22.4 linux/amd64. If you get a “command not found” error, the PATH isn’t set correctly — check the troubleshooting section below. - Set up your Go workspace — Go uses a module-based system now, so you don’t need a strict GOPATH. Create a folder for your project, e.g.,
mkdir helloandcd hello. Then rungo mod init helloto create ago.modfile — this marks the folder as a Go module. - Write a test program — Create a file named
main.goin that folder with the following content:package main import "fmt" func main() { fmt.Println("Hello, Go!") } - Run the program — In the terminal, run
go run main.go. You should seeHello, Go!printed. This confirms your installation and configuration are working. - Configure your editor (optional but recommended) — If you use VS Code, install the official Go extension from the marketplace. It gives you IntelliSense, debugging, and formatting. For JetBrains IDEs, install the Go plugin. After installing, open your project folder and let the extension prompt you to install additional tools (gopls, dlv, etc.) — accept them.
- Set environment variables (optional) — If you need to customize Go’s behavior, you can set environment variables like
GOPATH(default is~/go) orGOROOT(usually not needed). On Windows, use System Properties → Environment Variables; on macOS/Linux, add exports to your shell profile. Most users don’t need to change these.
Common Mistakes
- Not closing and reopening your terminal — After installation, the PATH change won’t take effect in already-open terminals. Always open a new terminal window.
- Mixing 32-bit and 64-bit versions — Download the correct architecture. Most modern systems are 64-bit; if you’re unsure, check your system info. Installing a 32-bit Go on a 64-bit system will fail.
- Forgetting to run
go mod init— Without ago.modfile, Go commands likego runmay still work, butgo buildorgo testmay complain about missing go.mod. Always initialize a module in a new project folder. - Editing PATH incorrectly on Linux — A typo in
~/.bashrccan break your shell. Double-check the export line, and always test withecho $PATHafter sourcing.
Tips
- Use the latest stable version — check the Go release page for updates. Older versions may lack security fixes.
- Keep your projects in separate folders with their own
go.mod— this is the modern Go way and avoids dependency conflicts. - Run
go fmton your code to format it automatically — it’s the standard style and makes collaboration easier. - Use
go envto see all your Go environment settings — useful for debugging configuration issues. - If you’re on Windows, consider using Windows Terminal for a better command-line experience.
Troubleshooting
- “go: command not found” — This means the PATH isn’t set. On Windows, reinstall the .msi to ensure PATH is set. On macOS, check if you installed via .pkg (should work) or manually — if manual, ensure you added
/usr/local/go/binto PATH. On Linux, re-check your export line and runsourceagain. - “go version” shows an old version — You may have multiple Go installations. Check
which goto see which one is being used. Remove the old one from PATH or uninstall it. - Permission denied when installing on Linux — Use
sudofor the extraction to/usr/local. If you don’t have sudo, extract to your home directory and set PATH accordingly. - VS Code Go extension not working — Ensure you have the Go extension installed and that it’s using the correct Go binary (check settings:
go.goroot). Also, install the recommended tools when prompted — if you missed the prompt, run “Go: Install/Update Tools” from the command palette. - “go: cannot find main module” — You’re running
go runoutside a module. Rungo mod initin the project folder first.
Frequently Asked Questions
Do I need to set GOPATH manually?
No. Since Go 1.11, modules are the default, and GOPATH is only used for the default location of downloaded dependencies (usually ~/go). You don’t need to set it unless you want to change where those dependencies are stored.
What’s the difference between go run and go build?
go run compiles and runs your program in one step, but doesn’t leave an executable behind. go build compiles the program and creates an executable file in the current directory (or the bin folder if you use go install).
How do I update Go to a newer version?
Download the new installer for your OS and run it — it will overwrite the old version. On Linux, you can also use sudo rm -rf /usr/local/go and then extract the new tar.gz. On macOS with Homebrew, run brew upgrade go.
Can I have multiple versions of Go installed?
Yes, but it requires manual setup. You can install different versions in separate directories and switch by changing your PATH or using a tool like g (go version manager). For most users, one version is sufficient.
Why is my Go program not running on Windows?
Check that you have the 64-bit version if your system is 64-bit. Also, ensure you’re running the command in the correct directory where your main.go file exists. If you get a “go: cannot find main module” error, run go mod init first.
Is Go free to use?
Yes, Go is open-source and free under a BSD-style license. You can use it for personal, commercial, and academic projects without any cost.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix msmpeg2vdec.dll Errors in Windows
- How to Update Sonos App and Speakers
- Unlock iPad Without Apple ID: Is It Possible?
- iOS 18 WhatsApp Notifications Not Working? Fix
- Fix Windows Cannot Locate Suitable Printer Driver
- Spotify Private Listening: Turn It On and Off