How to Install Go on Windows?
Published in
3 min readJun 9, 2024
Step 1: Download Go Installer
- Visit the Go download page:
- Go to the official Go download page.
- Download the Windows installer (MSI file) appropriate for your system architecture (most likely the 64-bit installer).
Step 2: Run the Installer
- Open the downloaded MSI file:
- Double-click the MSI file to run the installer.
2. Follow the installation prompts:
- Click “Next” to proceed with the installation.
- Accept the license agreement.
- Choose the installation directory (the default is usually fine).
- Complete the installation by clicking “Install” and then “Finish”.
Step 3: Set Up Environment Variables
- Open Environment Variables:
- Right-click on “This PC” or “My Computer” and select “Properties”.
- Click on “Advanced system settings”.
- Click on the “Environment Variables” button.
2. Update the PATH variable:
- In the “System variables” section, find the
Path
variable and select it. - Click “Edit” and add the path to the Go
bin
directory. By default, this isC:\Go\bin
.
3. Create a workspace directory:
- Create a directory for your Go workspace, e.g.,
C:\Users\<YourUsername>\go
.
4. Set the GOPATH environment variable:
- In the “User variables” section, click “New” and create a variable named
GOPATH
with the value set to your workspace directory (e.g.,C:\Users\<YourUsername>\go
).
Step 4: Verify the Installation
- Open Command Prompt:
- Press
Win + R
, typecmd
, and press Enter to open the Command Prompt.
2. Check the Go version:
- Type
go version
and press Enter. You should see the installed Go version displayed.
Step 5: Create and Run a Simple Go Program
- Create a new directory for your project:
- In the Command Prompt, navigate to your workspace directory
cd %GOPATH%
mkdir -p src/hello
cd src/hello
2. Create a Go file:
- Open your favorite text editor and create a file named
hello.go
with the following content in the hello directory:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
3. Run the Go program:
- In the Command Prompt, navigate to the directory where
hello.go
is located and run the program:
go run hello.go
- You should see
Hello, World!
printed in the Command Prompt.
Congratulations! You have successfully installed Go on Windows and run your first Go program.