Reputation: 301
I was reading through godoc on how I can keep my dependencies up to date: https://golang.org/ref/mod#build-commands
It says that -mod=mod
flag can be used to automatically update the go.mod file. But I am not able to use it.
This is the command that I tried:
% go get -mod=mod ./..
flag provided but not defined: -mod
usage: go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]
Run 'go help get' for details.
I am obviously missing something because I can't seem to get the flag to work.
Upvotes: 3
Views: 1950
Reputation: 5959
After some experiments, it looks that only quite old versions of Go understand go get -mod=
, in particular version 1.11. So the documentation is outdated and you could report it.
Officially recommended on Go version 1.14 or newer: to automatically update an existing go.mod
file and to download dependencies, instead of doing go get -mod=mod .
, simply run:
go get -d .
For the sake of the example being complete, you could now actually build everything and put binaries into $GOBIN
(or $GOPATH/bin
) with:
go install
If it still doesn't work, a couple of things to check:
go
to the latest versionThe online documentation that you are reading is always about the latest official version, while you might be using an older version. Check your version:
go version
With the current pace of Go development, most people are trying to update as soon as they can. Follow https://golang.org/doc/install
Apparently, there is no easy way to read older documentation online. Instead, I use godoc
tool to do it locally:
go get -v golang.org/x/tools/cmd/godoc
godoc -http=127.0.0.1:6060
Leave the above command running, then in your browser go to http://127.0.0.1:6060/cmd/go/
This way I've checked for example what the old docs said about -mod
flag.
Upvotes: 1