Install Go on Windows
This guide will help you install Go language on Windows system.
Download Go
First, download the Go installation package suitable for your Windows system from the official website.
Choose the corresponding version based on your system architecture:
windows-amd64- 64-bit Windows systemwindows-386- 32-bit Windows systemwindows-arm64- 64-bit ARM Windows system
Installation Methods
Method 1: Using MSI Installer (Recommended)
This is the simplest installation method, suitable for most users.
1. Download the installer
Download the .msi installation package from the official website.
2. Run the installer
Double-click the downloaded .msi file and follow the installer's prompts to complete the installation.
The installer will automatically:
- Install Go to
C:\Program Files\GoorC:\Program Files (x86)\Go - Configure the necessary environment variables
3. Verify installation
Open a new command prompt window (cmd) or PowerShell and execute:
go versionIf the installation is successful, you should see output similar to:
go version go1.21.3 windows/amd64Method 2: Using ZIP Archive
This method is suitable for users who need to manage multiple Go versions or install to a custom path.
1. Download the archive package
Download the .zip compressed package from the official website.
2. Extract to specified directory
Extract the downloaded .zip file to a specified directory, for example C:\Go.
3. Configure environment variables
You need to configure the following environment variables:
- Right-click "This PC" and select "Properties"
- Click "Advanced system settings"
- Click "Environment Variables"
Add the following environment variables:
GOROOT (Go installation directory):
C:\GoGOPATH (Go workspace directory):
C:\Users\YourUsername\goAdd the following to the Path environment variable:
%GOROOT%\bin
%GOPATH%\bin4. Restart command prompt
Close all command prompt windows and reopen them to make the environment variables take effect.
5. Verify installation
go versionConfigure GOPATH
By default, Go uses %USERPROFILE%\go as the workspace directory. If you want to use a different path, you can set the GOPATH environment variable.
The GOPATH directory structure is as follows:
GOPATH/
├── bin/ # Stores compiled executable files
├── pkg/ # Stores compiled package files
└── src/ # Stores source codeVerify Installation
Create a simple Go program to verify that the installation is successful:
1. Create project directory
mkdir C:\Users\YourUsername\hello
cd C:\Users\YourUsername\hello2. Create Go program file
Create a file named hello.go with the following content:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}3. Run the program
go run hello.goIf the output is Hello, World!, it means the installation is successful.
Uninstall
Uninstall MSI Installer Version
If you installed Go using the MSI installer:
- Open "Control Panel" > "Programs and Features"
- Find "Go Programming Language" in the program list
- Right-click and select "Uninstall"
Uninstall ZIP Archive Version
If you installed Go using the ZIP archive:
- Delete the Go installation directory (e.g.,
C:\Go) - Remove the Go-related environment variables from the environment variables settings
Troubleshooting
Command not found
If the go command is not found, please check:
- Whether the PATH environment variable is configured correctly
- Whether the environment variables have taken effect (restart command prompt)
- Check if the Go installation directory exists
Version mismatch
If the displayed version does not match the installed version, please check:
- Whether there are multiple Go installations
- Whether the PATH environment variable points to the correct Go installation directory
- Execute
where goto view the actual path of the go command
Permission denied
If you encounter a permission denied error:
- Run command prompt as administrator
- Check if you have write permissions to the installation directory
Module proxy issues
If you encounter issues downloading modules, you can configure a module proxy:
go env -w GOPROXY=https://goproxy.cn,directUsing PowerShell
It is recommended to use PowerShell instead of cmd, as PowerShell provides better command-line experience.
Check environment variables
$env:GOROOT
$env:GOPATH
$env:PATHSet environment variables (temporary)
$env:GOROOT = "C:\Go"
$env:GOPATH = "C:\Users\YourUsername\go"
$env:PATH += ";$env:GOROOT\bin;$env:GOPATH\bin"Set environment variables (permanent)
To permanently set environment variables in PowerShell, you can use the [System.Environment] class:
[System.Environment]::SetEnvironmentVariable("GOROOT", "C:\Go", "User")
[System.Environment]::SetEnvironmentVariable("GOPATH", "C:\Users\YourUsername\go", "User")Next Steps
After installation is complete, you can:
- Visit Go Getting Started Guide to learn Go language basics
- Visit Official Documentation for more detailed documentation
- Visit Go Tour to learn through interactive tutorials
- Visit Go Playground to run Go code online
Recommended Tools
- IDE: GoLand (paid), Visual Studio Code (free)
- Terminal: Windows Terminal, PowerShell 7+
- Package Manager: Chocolatey, Scoop (can be used to install Go)
Installing Go using Chocolatey
choco install golangInstalling Go using Scoop
scoop install go