golangtutorialAll tutorials

How to Download and Install Golang Safely

Download and install Golang on Windows, macOS, or Linux, verify the active toolchain, and avoid PATH and multiple-installation problems.

Fundamentals · Lesson 5Saved in this browser. No account required.

Install Go from the official distribution, verify which executable your shell selected, and run a program that reports its target platform. These steps cover Windows, macOS, and Linux while avoiding the PATH conflicts that cause most setup failures.

The tested program supports Go 1.22 and later. Its output was observed with Go 1.24.7 on Windows amd64.

Choose the correct official Go package

Open the official Go downloads page and select the current supported release for your operating system and processor architecture. Use amd64 for most 64-bit Intel or AMD computers and arm64 for current ARM devices such as Apple silicon and Windows on ARM.

Do not download a package based only on the browser or operating-system label. A mismatched architecture may refuse to start or depend on translation. If you are unsure, check the operating system’s hardware information before choosing.

The wider Go tutorial begins after installation and takes you through language and standard-library fundamentals.

Install Go on your operating system

Windows

Download the Windows installer from go.dev and run it. Accept the standard installation location unless your organization manages developer tools elsewhere. Close and reopen PowerShell, Command Prompt, and editor terminals so they inherit the updated PATH.

Verify the command and its location:

go version
Get-Command go

If Get-Command points to an old location, remove the stale PATH entry or uninstall the older distribution. Reopen the shell and check again.

macOS

Download the package installer that matches Apple silicon or Intel and complete the installer. Open a new terminal, then run:

go version
command -v go

If a package manager installation also exists, command -v go shows which one wins. Keep one intentional installation path or document why the machine needs several versions.

Linux

Follow the official Linux installation instructions. The archive installation replaces the Go distribution directory, then adds its bin directory to PATH. Never extract a new archive over an old Go directory because obsolete files can remain.

Open a new shell and verify:

go version
command -v go

System package repositories may ship a different release cadence. Use them only when that tradeoff is deliberate and the selected version meets the project’s requirement.

Verify the toolchain with a real program

Create a new directory outside the Go installation itself. Save this as main.go:

package main

import (
	"fmt"
	"runtime"
)

func main() {
	if runtime.GOOS == "" || runtime.GOARCH == "" {
		fmt.Println("toolchain target is unavailable")
		return
	}

	fmt.Println("Go installation works")
	fmt.Printf("target: %s/%s\n", runtime.GOOS, runtime.GOARCH)
}

Run it with go run main.go.

Output:

Go installation works
target: windows/amd64

The second line should match your operating system and architecture. Continue with your first Go program to learn what each part of the file does.

Create a module before building a project

A one-file experiment can run directly, but a project should have a module path. In an empty project directory run:

go mod init example.com/hello
go run .

The module path identifies packages. It does not need to resolve on the internet for local practice, though published modules should use a path you control. The compilation and execution guide explains how go run, go build, and go install use that module.

Do not create a global GOPATH workspace for ordinary module-based development. Modern Go projects declare dependencies in go.mod; the toolchain manages downloaded modules and build caches separately.

Diagnose setup with go env

Run go env GOROOT GOPATH GOMOD GOOS GOARCH from the project directory. GOROOT identifies the active distribution. GOPATH remains a cache and installation workspace, but it is not where every project must live. GOMOD shows the active module file or indicates that no module applies.

When an editor disagrees with the shell, restart it and compare its environment. The Golang IDE overview provides a workflow for testing editor integration.

Common mistakes

Keeping an old Go executable earlier in PATH

Installing a new release does not guarantee that the shell selects it. Check the resolved executable with Get-Command go on Windows or command -v go on macOS and Linux.

Editing GOROOT manually

Most standard installations discover GOROOT from the executable. A stale manual setting can point the new command at old standard-library files. Remove the override unless a documented environment requires it.

Writing projects inside the installation directory

The Go distribution is toolchain software, not a project workspace. Keep projects in a normal user or repository directory so upgrades cannot overwrite them.

What next

Write and explain your first Go program, then configure an editor using the Golang IDE overview. When you need a reusable binary, continue to Go compilation and execution.