Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GOBIN not set: cannot run go install

Tags:

go

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?

like image 252
user3918985 Avatar asked Aug 09 '14 08:08

user3918985


People also ask

Should 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.

What is Gopath Goroot and Gobin?

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.

Where should I set Gopath?

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.


2 Answers

I set the GOBIN path and that worked for me

export GOBIN=[WorkspacePath]/bin 
like image 91
Pratik Goenka Avatar answered Sep 27 '22 20:09

Pratik Goenka


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
  • you have a 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 in DIR/src/foo/quux is installed into DIR/bin/quux, not DIR/bin/foo/quux. The "foo/" prefix is stripped so that you can add DIR/bin to your PATH to get at the installed commands.

If the GOBIN environment variable is set, commands are installed to the directory it names instead of DIR/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 the go 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.

like image 32
VonC Avatar answered Sep 27 '22 20:09

VonC