I am trying to install my custom package for my main.go file. However, when I ran
go install custom.go
I got this error
go install: no install location for .go files listed on command line (GOBIN not set)
How do I set GOBIN?
Setting GOBIN environment variable is not necessary, but since bin directory of a workspace will be in our PATH , it's a good idea to set it for simplicity.
The GOPATH may contain multiple directory paths that refer to different Go projects. The GOBIN environment variable refers to the bin directory inside the go installation directory such as $GOROOT/bin.
The GOPATH environment variable specifies the location of your workspace. It defaults to a directory named go inside your home directory, so $HOME/go on Unix, $home/go on Plan 9, and %USERPROFILE%\go (usually C:\Users\YourName\go ) on Windows.
I set the GOBIN path and that worked for me
export GOBIN=[WorkspacePath]/bin
Update 2020: since Go 1.11 and the introduction of Go modules, GOPATH
is not needed anymore per project, and defaults to ~/go
for global tools/project you would go get
.
Go 1.16 (Q1 2020) should default GOBIN
to GOPATH[0]/bin
.
But for now, for any project using modules, you would not have an error message like "go install: no install location ...
" anymore.
Original answer 2014:
Check your GOPATH
variable.
Make sure:
- your sources are under
GOPATH/src
bin
folder within your GOPATH folder.See GOPATH environment variable (where 'DIR' is a GOPATH
folder):
The
bin
directory holds compiled commands.
Each command is named for its source directory, but only the final element, not the entire path. That is, the command with source inDIR/src/foo/quux
is installed intoDIR/bin/quux
, notDIR/bin/foo/quux
. The "foo/
" prefix is stripped so that you can addDIR/bin
to yourPATH
to get at the installed commands.
If the
GOBIN
environment variable is set, commands are installed to the directory it names instead ofDIR/bin
.GOBIN
must be an absolute path.
For instance, this thread illustrates what happen in the case where a go build is done outside of GOPATH/src
:
Looks like your
GOPATH
is set to~/go
but you ran thego install
command on~/dev/go
See Go Build
The Go path is a list of directory trees containing Go source code. It is consulted to resolve imports that cannot be found in the standard Go tree.
If you have done go build
, you can also try a go install
(no custom.go
): you want to install the package, not a single file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With