To write Go you need the Go toolchain: the compiler, the standard library and
the go command. This lesson installs Go on Windows, macOS or Linux, checks that
it works, and clears up the old questions about GOPATH.
Download from go.dev/dl
The official downloads live at go.dev/dl. The page offers
an installer or archive for every platform, and it always highlights the current
stable release. When in doubt, pick the package that matches your operating
system and CPU (most modern machines use the amd64 or arm64 build).
Install on Windows
Download the .msi installer from go.dev/dl and double-click it. The wizard
copies Go to C:\Program Files\Go and adds the go command to your PATH
automatically. Close and reopen your terminal afterwards so the new PATH is
picked up.
If you prefer a package manager, winget works too:
winget install GoLang.Go
Install on macOS
The simplest option is Homebrew:
brew install go
Alternatively, download the .pkg installer from go.dev/dl and run it; it
installs Go to /usr/local/go and puts go on your PATH.
Install on Linux
Use the official archive from go.dev/dl. Remove any old install first, then
extract the new one into /usr/local (replace the version number with the
current release):
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.24.0.linux-amd64.tar.gz
Then add Go’s bin directory to your PATH by appending this line to
~/.profile (or ~/.bashrc):
export PATH=$PATH:/usr/local/go/bin
Open a new terminal, or run source ~/.profile, so the change takes effect.
Verify the installation
Whatever your platform, confirm Go is available by printing its version:
go version
You should see a line similar to this one:
go version go1.24.0 linux/amd64
If instead you get “command not found”, your PATH is not set yet — reopen the
terminal or re-check the PATH step for your operating system.
Do I still need GOPATH?
No. Since Go modules became the default (Go 1.16), you keep your projects
anywhere on disk. You no longer place source code under GOPATH/src, and you
do not set GO111MODULE by hand.
GOPATH still exists — it defaults to ~/go — but now it is only a cache and
tools directory: downloaded dependencies land in GOPATH/pkg/mod, and binaries
installed with go install land in GOPATH/bin. A project becomes a module as
soon as it contains a go.mod file, which you create with go mod init. That
single file, not a special folder, defines your workspace.
Run a program to confirm it works
The best proof that Go is installed is running a real program. Create a file
called hello.go with the following complete program:
package main
import "fmt"
func main() {
fmt.Println("Go is installed!")
}
From the same folder, run it with:
go run hello.go
Go compiles and executes the file, printing:
Go is installed!
Common mistakes
- Forgetting to reopen the terminal.
PATHchanges only apply to new shells, sogo versionmay fail until you open a fresh terminal. - Keeping two installs. Installing via Homebrew and the
.pkgcan leave twogobinaries; check which one wins withwhich go. - Recreating GOPATH by habit. You do not need a
~/go/srcfolder for your projects anymore — ago.modfile is enough.
Practice
Install Go using the method for your platform, verify it with go version, then
write and run a program that prints your name in a greeting.
Show the solution
After go version prints a version line, create greeting.go:
package main
import "fmt"
func main() {
fmt.Println("Hello, I am learning Go!")
}Run it with go run greeting.go. Seeing your message in the terminal confirms
that the compiler and standard library are both working.
Summary
- Download Go from go.dev/dl, or use
brew install go/winget/ the Linux archive. - Confirm the install with
go version, then run a program withgo run. - Modules replaced
GOPATHfor organising code: ago.modfile defines your project, wherever it lives.
With Go installed, you are ready to build your first Go program, and then move on to variables and types.