go: command not found
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
GOROOTenvironment 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.gzVerify the installation:
/usr/local/go/bin/go version
go version go1.22.2 linux/amd642. 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/binApply the changes:
source ~/.bashrc # or source ~/.zshrc
go version3. 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/bin4. Verify the GOROOT variable (if set)
Check that GOROOT points to the correct installation directory:
echo $GOROOT
# Should output: /usr/local/goIf it is set incorrectly, unset or correct it:
unset GOROOT
# Or set it correctly:
export GOROOT=/usr/local/go5. Restart your terminal session
After making changes, open a new terminal or run exec $SHELL to reload your shell environment.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro