no replace directive allowed for "go install" ?

3,349 views
Skip to first unread message

Sebastien Binet

unread,
Oct 27, 2021, 10:06:32 AM10/27/21
to golang-nuts
hi there,

I was updating instructions to install binaries for a package of mine,
with Go modules enabled.

and I got:

$> cd /tmp/dir
$> go install -v go-hep.org/x/hep/cmd/root2yoda@latest
go: downloading go-hep.org/x/hep v0.29.2
go: go-hep.org/x/hep/cmd/root2yoda@latest (in go-hep.org/x/h...@v0.29.2):
The go.mod file for the module providing named packages contains one or
more replace directives. It must not contain directives that would cause
it to be interpreted differently than if it were the main module.

why is that?
the replace directive is the following one:
replace github.com/apache/arrow/go/arrow => git.sr.ht/~sbinet/go-arrow v0.1.1

(it's the only one.)

I'd assume the error message above is for the cases where the replace
directive points at a local module, but shouldn't be displayed in this
case, right?

I am using:

$> go version
go version devel go1.18-cfb532158f Wed Oct 27 13:12:49 2021 +0000 linux/amd64

cheers,
-s

Zik Aeroh

unread,
Oct 27, 2021, 9:54:51 PM10/27/21
to golang-nuts
All replaces are disallowed when using "go install" with a version number, regardless of what kind they are; see https://github.com/golang/go/issues/40276, specifically the sections about "replace".

I have a tool I'm currently rewriting that manages $GOBIN via a config file; I'm relying on "go install" where possible, but for modules that have replaces (for me, gopls at master), a workaround is to use a temporary module to pull everything in, copy over the replacements, then use a version-less "go install". 
Reply all
Reply to author
Forward
0 new messages