Go install does not recognize the -o flag

I am trying to do go install and rename the output with the -o flag.

 go install -o bar.exe src/foo.go 

But this is not an error:

 flag provided but not defined: -o usage: install [build flags] [packages] 

go help build shows -o as the correct build flag to rename the output binary. There is no mention that this flag is not defined for go install .

go run -o bar.exe src/foo.go does not work with the same error.

go build -o bar.exe src/foo.go works. I get bar.exe.

So is this just a documentation error, or am I missing something?

My version: go1.5 windows/386 .

Thanks.

+8
source share
2 answers

go build accepts the -o flag, but go install does not.

go install will always be displayed on $GOPATH/bin

If you want to install a custom binary name in your gopath, you can do go build -o $GOPATH/bin/whatever , and that would be roughly equivalent to go install

+27
source

You can fake the -o flag if all you care about is the location, not the name of the binary. Define GOBIN for the install command:

 GOBIN='readlink -f my/location' go install some/persons/go-package 

Caution: this does not work for cross-compiled binaries.

0
source

All Articles