The $GOPATH variable is not being recognized by go env, and the go install command is attempting to install packages to the default GOROOT location (/usr/lib/go) instead of the intended GOPATH directory.
The issue may be related to an incorrect or improperly exported $GOPATH.
To resolve the issue, ensure that $GOPATH is set and exported correctly. Here are the steps to do so:
Create the necessary directories within $GOPATH:
mkdir -p $HOME/dev/go/src mkdir -p $HOME/dev/go/bin
Add the following lines to $HOME/.profile:
export GOPATH=$HOME/dev/go export PATH=$PATH:$HOME/dev/go/bin
Source the profile file:
source $HOME/.profile
Verify the settings:
env | grep -i '^GO' cat $HOME/.profile
You should see $GOPATH set to the correct directory /home/me/dev/go. If the issue persists after following these steps, consider upgrading to a newer version of Go, as the problem may have been resolved in a subsequent release.
The above is the detailed content of Why Is go install Installing to GOROOT Instead of GOPATH?. For more information, please follow other related articles on the PHP Chinese website!