"go install" Error: "No Install Location for Directory Outside GOPATH"
When installing Go into a directory outside of GOPATH, such as the one you have set up within the "~/go" directory, you may encounter the error message "go install: no install location for directory /Users/Daryl/go/src/tire outside GOPATH." This issue arises because Go typically installs executables and packages within GOPATH's "bin" directory.
To resolve this error and correctly install your Go project, you can either modify your $GOBIN environment variable or add it to your OS search path. Here are the steps for each approach:
Option 1: Set $GOBIN to $GOPATH/bin
In your terminal, run the following command to set $GOBIN to the "bin" directory within GOPATH:
export GOBIN=$GOPATH/bin
Option 2: Add $GOBIN to OS Search Path
Edit your operating system's search path to include $GOBIN. For example, on macOS, you can add the following line to your .bash_profile or .zshrc file:
export PATH=$PATH:$GOBIN
Once you have made the necessary changes, you can re-run your "go install" command and the project should be installed successfully.
The above is the detailed content of How to Resolve 'go install: no install location for directory outside GOPATH' Error?. For more information, please follow other related articles on the PHP Chinese website!