Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go 1.5 : Is "go install" behaviour changed? Removing stale executables?

Tags:

bash

go

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?

like image 441
Mayank Patel Avatar asked Aug 24 '15 10:08

Mayank Patel


People also ask

What is the use of go install?

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.

How do I install a specific version of go?

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.

Where does go install by default?

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.

How do you remove packages installed with go install?

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


1 Answers

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.

like image 181
Ainar-G Avatar answered Nov 02 '22 07:11

Ainar-G