When attempting to install Go packages located outside the GOPATH using go install, you may encounter the following error:
go install: no install location for directory /Users/me/src/go-statsd-client outside GOPATH
This error occurs because go install cannot automatically determine the appropriate install location for packages that reside outside the designated GOPATH.
To resolve this issue, you need to explicitly set the GOBIN environment variable to specify the desired installation directory. This step is often overlooked, especially among macOS users.
For macOS users specifically, follow these steps:
Create a bin directory within your GOPATH:
mkdir ${GOPATH}/bin
Set the GOBIN environment variable to the newly created directory:
export GOBIN=${GOPATH}/bin
Run go install again to install the package into the specified directory:
go install
By setting GOBIN, you direct go install to place the installed binaries and packages in the desired location. This will prevent the error related to no install location outside the GOPATH and ensure a successful installation process.
The above is the detailed content of Why Does `go install` Fail with 'No Install Location' Outside `GOPATH`?. For more information, please follow other related articles on the PHP Chinese website!