GOPATH and GOBIN: Resolving "go install" Installation Error
You encounter the error "go install: no install location for directory outside GOPATH" when attempting to install the "tire" project. This issue stems from the location of your project and the configuration of the GOPATH and GOBIN environment variables.
GOPATH and GOBIN
GOPATH is an environment variable that defines the workspace for Go projects. It specifies the root directory where all Go projects, source code, and dependencies are located. GOBIN, on the other hand, specifies the location where Go binaries will be installed.
Resolution
To resolve this error, you need to ensure that the installation location specified by GOBIN is either within the GOPATH or added to your OS search path. There are two possible solutions:
1. Set GOBIN to $GOPATH/bin
Run the following command to set GOBIN to the "bin" directory within your GOPATH:
export GOBIN=$GOPATH/bin
This places the installed binaries within the GOPATH, resolving the issue.
2. Add GOBIN to PATH
If you prefer to keep GOBIN separate from GOPATH, you can add it to your PATH environment variable by running the following command:
export PATH=$PATH:$GOBIN
This allows your system to locate installed binaries from within GOBIN without explicitly specifying the path.
Conclusion
By configuring either GOBIN to be within GOPATH or adding it to your PATH, you can successfully install Go projects using "go install" and overcome the "no install location outside GOPATH" error.
The above is the detailed content of Why am I getting the 'go install: no install location for directory outside GOPATH' Error?. For more information, please follow other related articles on the PHP Chinese website!