Home >Backend Development >Golang >How to Fix 'go install: no install location for directory outside GOPATH'?

How to Fix 'go install: no install location for directory outside GOPATH'?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-10 13:59:03309browse

How to Fix

"go install: no install location for directory outside GOPATH" Error Resolved

When attempting to install Go projects located outside the GOPATH, developers often encounter the error "go install: no install location for directory outside GOPATH." This issue occurs because Go looks for the environment variable path $GOBIN by default. To resolve this issue, one can either set $GOBIN to $GOPATH/bin or add $GOBIN to the OS search path.

To achieve the first method, run the following command:

$ export GOBIN=$GOPATH/bin

The second method requires adding $GOBIN to the OS search path. Execute the following command:

$ export PATH=$PATH:$GOBIN

After implementing either of these steps, the "go install" command can be executed outside the GOPATH without encountering the error.

The above is the detailed content of How to Fix 'go install: no install location for directory outside GOPATH'?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn