What does `go install path/to/main.go` do with GO111MODULE=on?

85 views
Skip to first unread message

Matt Mueller

unread,
Mar 10, 2021, 5:59:25 PM3/10/21
to golang-nuts
Hey folks, 

I'm trying to install a command inside a module globally on my system so that I can use that binary elsewhere. During the $GOPATH era this worked something like this:

go install cmd/app/main.go
// installed app to $GOPATH/bin

Unfortunately that doesn't seem to work anymore. It doesn't error, but I don't know where it installed the binary. Not in $GOPATH/bin.

I've read the documentation for `go help install`. It pointed me to `go help modules`, but then I got lost after that.

Any pointers would be greatly appreciated. Thanks!

Matt

Kurtis Rader

unread,
Mar 10, 2021, 6:08:09 PM3/10/21
to Matt Mueller, golang-nuts
Do you have environment var GOBIN set? Check the output of "go env GOBIN". See https://golang.org/ref/mod#mod-commands.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ad5e444b-7d40-464b-9848-e2135d1788e0n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Matt Mueller

unread,
Mar 10, 2021, 6:20:50 PM3/10/21
to golang-nuts
Thanks for the message! Unfortunately, 

GOBIN=$GOPATH/bin go install ./cmd/app/main.go

Doesn't change anything. Actually I'm realizing that even without go modules but with $GOPATH this never installed anywhere:

GOBIN=$GOPATH/bin GO111MODULE=off go install ./cmd/testinstall/main.go

You have to do:

cd ./cmd/app && go install

Then it appears to work in all cases. 

I'm assuming this is by design, but it feels to me like go install ./cmd/app/main.go silently failing is a bug.

Is this worth opening an issue for?

jake...@gmail.com

unread,
Mar 10, 2021, 6:35:27 PM3/10/21
to golang-nuts
What version of Go are you using?

Dan Kortschak

unread,
Mar 10, 2021, 6:36:26 PM3/10/21
to golan...@googlegroups.com
On Wed, 2021-03-10 at 15:20 -0800, Matt Mueller wrote:
> I'm assuming this is by design, but it feels to me like go install
> ./cmd/app/main.go silently failing is a bug.
>
> Is this worth opening an issue for?

If it's a bug it's an error reporting bug. The go install command is
documented to take only package paths, not file paths.

```
- Arguments must be package paths or package patterns (with "..." wildcards).
They must not be standard packages (like fmt), meta-patterns (std, cmd,
all), or relative or absolute file paths.
```


Reply all
Reply to author
Forward
0 new messages