Till Go 1.4.2 when i run go install after running go build, i could find binary file in my current folder. Hence following Linux command was working
$ go build && go install && ./executable
But after installing go 1.5, when i run same command i get,
-bash: ./executable: No such file or directory
and when i checked, there is no executable to find. Did go install behavior changed in Go 1.5?
The go build command compiles the packages, along with their dependencies, but it doesn't install the results. The go install command compiles and installs the packages.
We can use the go install command to download install individual versions of Go. Running go install golang.org/dl/go<version>@latest will download and install a wrapper Go command for the specific Go version.
By default, the installer will install Go to Program Files or Program Files (x86) . You can change the location as needed. After installing, you will need to close and reopen any open command prompts so that changes to the environment made by the installer are reflected at the command prompt.
If you want to remove the packages installed with the go get command – we can directly delete the files/directories related to the installed package. We have to delete the source directory under $GOPATH/src and compiled package file under $GOPATH/pkg/<architecture>.
Yes, the behaviour has changed in Go 1.5:
If 'go install' (with no arguments, meaning the current directory) succeeds, remove the executable written by 'go build', if present. This avoids leaving a stale binary behind during a sequence like:
go build <test, mostly works, make small change> go install
Before this CL, the current directory still has the stale binary from 'go build'. If $PATH contains dot, running the name of the program will find this stale binary instead of the new, installed one.
I can't find anything mentioning that in the release notes though. Might be a documentation issue.
It seems like the solution is to use the binary that go install
has produced.
EDIT: Here is the issue on the Go issue tracker if you want to follow on updates. Should be fixed by 1.5.1.
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