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