Installation
What you will learn
By the end of this lesson you will have a working Go installation that you have verified yourself, you will know what the installer put on your machine, and you will have an editor that formats your code and flags errors as you type.
What you are installing
Go is not just a compiler. The download is the Go toolchain: the go command (which builds, runs, tests, and manages dependencies), the compiler itself, the gofmt formatter, and the entire standard library. Everything you need is in one package, with no separate package manager or build tool to add.
Install Go
Pick the right download
Choose the package for your operating system and processor. If you are unsure of your processor:
- Windows: open Settings → System → About. "x64-based processor" means
amd64. Most PCs are this. - macOS: run
uname -min Terminal.arm64means Apple silicon (M1 or later), andx86_64means Intel. - Linux: run
uname -m.x86_64meansamd64, andaarch64meansarm64.
Run the installer
Windows: run the .msi file and accept the defaults. The installer adds Go to your PATH automatically.
macOS: open the .pkg file and follow the wizard. Go is installed to /usr/local/go.
Linux: download the .tar.gz archive, then remove any old installation and extract the new one. Replace the filename with the one you downloaded:
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.x.x.linux-amd64.tar.gz
Linux does not update PATH for you. Add this line to ~/.profile (or ~/.zshrc if you use zsh):
export PATH=$PATH:/usr/local/go/bin
Open a new terminal
This step matters. Installers change your PATH, and a terminal that was already open will not see the change. Close it and open a new one. On Linux, either do the same or run source ~/.profile.
Verify the installation
go version
You should see output like this:
go version go1.x.x windows/amd64
The version number and the operating system and processor will match your own machine. If you see this line, Go is installed.
Look at the environment
Go keeps its configuration in a set of environment settings. Print them all with:
go env
That is a long list, so ask for two specific ones:
go env GOROOT GOPATH
| Setting | What it is | Typical value |
|---|---|---|
GOROOT | Where the Go toolchain itself is installed | /usr/local/go or C:\Program Files\Go |
GOPATH | A folder where Go stores downloaded modules, installed tools, and caches | ~/go or C:\Users\you\go |
You rarely need to change either. Older Go tutorials told you to keep all your code inside GOPATH. That is no longer true. Today every project is a module, and it can live in any folder on your machine. You will create your first module in the next lesson, and GOPATH just quietly holds the files that Go downloads on your behalf.
GOROOT by hand. The installer already gets it right, and a wrong value causes confusing errors.If go is not recognised
You might see go: command not found on macOS and Linux, or 'go' is not recognized as an internal or external command on Windows. That means your terminal cannot find the go program. Work through this order:
- Open a new terminal. This fixes most cases.
- Check where the terminal is looking.
| System | Find go | Show PATH |
|---|---|---|
| Windows (PowerShell) | Get-Command go | $env:Path -split ';' |
| Windows (Command Prompt) | where go | echo %PATH% |
| macOS and Linux | which go | echo $PATH |
- Make sure Go's
binfolder is in the list. It is usuallyC:\Program Files\Go\binon Windows and/usr/local/go/binon macOS and Linux. If it is missing, add it. On Windows use Settings → search "Environment Variables" → editPath. On macOS and Linux add theexport PATH=...line shown earlier to your shell profile. - Reopen the terminal again after any change.
Essential commands
You will use these constantly, so it is worth skimming the list now.
| Command | What it does | When you will use it |
|---|---|---|
go version | Prints the installed version | Checking your setup |
go run . | Builds and runs the package in the current folder | Trying your code |
go build . | Builds an executable and keeps it | Producing a program to share |
go test ./... | Runs tests in every package below this folder | Checking nothing broke |
go fmt ./... | Formats code in Go's standard style | Before every commit |
go mod tidy | Syncs go.mod with the imports in your code | After adding or removing imports |
go doc fmt.Println | Shows documentation in the terminal | Looking up a function |
Try go doc right now:
go doc fmt.Println
It prints the function signature and description without opening a browser. Reading documentation this way is a habit that pays off all through the course.
Set up your editor
You can write Go in any text editor, because the Go toolchain does the real work. A good editor adds comfort: it formats on save, underlines compiler errors as you type, completes names, and jumps to definitions. These features come from a helper program called gopls, the official Go language server.
The easiest setup is VS Code:
- Install Visual Studio Code.
- Open the Extensions panel and install Go, published by the Go Team at Google.
- Open the Command Palette (
Ctrl+Shift+P, orCmd+Shift+Pon macOS) and run Go: Install/Update Tools. Select everything, includinggopls, and confirm. - Open any
.gofile. On saving, the extension formats the file automatically.
GoLand, Neovim, and other editors work too. What matters is that they use gopls and gofmt, so you get the same experience.
Practice
- Run the command that shows your installed Go version.
- Print only your
GOROOTandGOPATH. - Imagine the terminal says
go: command not found. Write the first three things you would check.
go versiongo env GOROOT GOPATH- First, close the terminal and open a new one, because it may simply not have loaded the updated
PATH. Second, runwhich go(macOS and Linux),where go(Command Prompt), orGet-Command go(PowerShell) to see whether the terminal can find the program. Third, check that Go'sbinfolder, such as/usr/local/go/binorC:\Program Files\Go\bin, appears inPATH, and add it if not.
Summary
Install Go from the official download page, open a new terminal, and confirm it with go version. The installer provides the compiler, the formatter, and the standard library in one package. GOROOT is where Go lives and GOPATH is where it keeps downloaded files, and neither limits where your own projects go. If the go command is missing, the fix is almost always about PATH. An editor with gopls makes learning smoother, but the toolchain itself does the real work.
Official reference: Download and install Go.
Ready to wrap up?
Mark this complete when you can explain the main idea and finish the practice task.