Home >Backend Development >Golang >Why Does `go install` Ignore My `GOPATH` Setting and Install to `GOROOT`?
go install Defaulting to GOROOT when GOPATH is Set
In an encounter with a perplexing issue, a user discovered that go install persisted in using GOROOT as the installation destination, neglecting the set GOPATH.
Upon investigating, it emerged that despite the environment variable $GOPATH being set to /home/me/dev/go, go env failed to recognize it. This anomaly caused go install to attempt installing packages in /usr/lib/go.
The user's initial attempts of setting $GOPATH in ~/.profile and sourcing it proved futile. However, the problem mysteriously resolved after upgrading to Go 1.1beta2.
To provide a possible solution, it is essential to establish the GOPATH workspace. The following steps outline the process:
Create directories for source code and binaries:
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
Immediately after logging in, verify the settings:
env | grep -i '^GO'
This process establishes a custom workspace for Go. If GOPATH is still not recognized, post the output of the supplied commands for further assistance.
The above is the detailed content of Why Does `go install` Ignore My `GOPATH` Setting and Install to `GOROOT`?. For more information, please follow other related articles on the PHP Chinese website!