2.3 Verifying Installation

After installing Go, it's important to verify that everything is set up correctly.

Checking Go Version

The simplest way to verify your installation is to check the Go version:

go version

Expected output

go version go1.23.x linux/amd64

The output shows:

Verifying PATH Configuration

Go needs to be in your system PATH for the go command to work from any directory.

On Unix-like systems (macOS/Linux)

Check if Go is in your PATH:

which go

This should output something like /usr/local/go/bin/go or /usr/bin/go.

If which go returns nothing, you need to add Go to your PATH. Add this line to your ~/.bashrc, ~/.zshrc, or ~/.profile:

export PATH=$PATH:/usr/local/go/bin

Then reload your shell:

source ~/.bashrc  # or source ~/.zshrc

On Windows

Open Command Prompt and check:

where go

This should show the path to go.exe, typically C:\Program Files\Go\bin\go.exe.

Testing Installation

Let's verify that Go can compile and run programs. Create a simple test:

# Create a test directory
mkdir ~/go-test
cd ~/go-test

# Create a simple Go file
cat > hello.go << 'EOF'
package main

import "fmt"

func main() {
    fmt.Println("Go installation successful!")
}
EOF

# Run the program
go run hello.go

Expected output

Go installation successful!

If you see this output, congratulations! Go is installed and working correctly.

Checking Go Environment

Go provides a command to check your Go environment configuration:

go env

This displays important environment variables like:

You can check a specific variable:

go env GOROOT
go env GOPATH