Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go install does not recognize "-o" flag

Tags:

go

I'm trying to do a go install and rename the output with the -o flag.

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

But this fails with the 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 fails with the same error.

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

So is this just an error of documentation, or have I missed something?

My version: go1.5 windows/386.

Thanks.

like image 528
theeddieh Avatar asked Oct 20 '15 17:10

theeddieh


People also ask

How do you use go install command?

The go install command behaves almost identically to go build , but instead of leaving the executable in the current directory, or a directory specified by the -o flag, it places the executable into the $GOPATH/bin directory. To find where your $GOPATH directory is located, run the following command: go env GOPATH.

How do I run a go package?

Add the Go install directory to your system's shell path. That way, you'll be able to run your program's executable without specifying where the executable is. Once you've updated the shell path, run the go install command to compile and install the package. Run your application by simply typing its name.

Where does go install put binaries?

Much like the previous behaviour of go get , go install places binaries in $GOPATH/bin , or in $GOBIN if set. See the “Setting up your PATH “ section in Installing Go to ensure your PATH is set correctly.

Does go build install dependencies?

Installing missing dependenciesYou may also run go build or go test command to install all the missing dependencies automatically. If you run go build, the command will fetch the missing package automatically and include it to your go. mod file before your project is compiled.


Video Answer


1 Answers

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

go install will always output to $GOPATH/bin

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

like image 149
captncraig Avatar answered Oct 07 '22 20:10

captncraig