Skip to content
go: command not found

go: command not found

DodaTech 2 min read

The “go: command not found” error means your shell cannot locate the Go compiler binary. This happens when Go is not installed or its executable path is missing from your system’s PATH environment variable.

What It Means

When you type go version or any go command, your operating system searches through directories listed in the PATH environment variable. If the Go binary is not found in any of those directories, the shell returns “go: command not found”.

Why It Happens

  • Go is not installed on your system.
  • Go is installed but the binary directory is not in your PATH.
  • You installed Go via a package manager that placed it in a non-standard location.
  • Your shell configuration (.bashrc, .zshrc, .profile) does not include the Go binary path.
  • The GOROOT environment variable is set incorrectly, pointing to a non-existent directory.

How to Fix It

1. Install Go from the official source

Download the latest Go release from golang.org/dl:

# Linux (adjust version as needed)
wget https://go.dev/dl/go1.22.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.22.2.linux-amd64.tar.gz

Verify the installation:

/usr/local/go/bin/go version
go version go1.22.2 linux/amd64

2. Add Go to your PATH

Add the Go binary directory to your shell configuration file:

# Add to ~/.bashrc or ~/.zshrc
export PATH=$PATH:/usr/local/go/bin

Apply the changes:

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

3. Set up GOPATH for your projects

Go expects a workspace directory. Add these lines to your shell config:

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

4. Verify the GOROOT variable (if set)

Check that GOROOT points to the correct installation directory:

echo $GOROOT
# Should output: /usr/local/go

If it is set incorrectly, unset or correct it:

unset GOROOT
# Or set it correctly:
export GOROOT=/usr/local/go

5. Restart your terminal session

After making changes, open a new terminal or run exec $SHELL to reload your shell environment.

FAQ

Do I need to set GOROOT manually?
Modern Go installations do not require GOROOT to be set. The Go toolchain detects its own location automatically. Setting GOROOT is only needed in custom or multi-version setups.
What is the difference between GOROOT and GOPATH?
GOROOT points to the Go installation directory (where the compiler and standard library live). GOPATH points to your workspace where your projects and dependencies are stored. Since Go 1.16, GOPATH is optional when using Go modules.
Should I install Go using a package manager like apt or brew?
Package managers often distribute older Go versions. Download from golang.org for the latest stable release. If using a package manager, verify the version with go version after installation.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro