Getting GOPATH error "go: cannot use path@version syntax in GOPATH mode" in Ubuntu 16.04

Solution 1:

I had the same issue and solved setting specific env variable export GO111MODULE=on in my .zshrc(or .bashrc depending on which shell you use) and restart the shell in order to enable modules. You can find more details here: https://github.com/golang/go/wiki/Modules

Solution 2:

As you already noticed, you should use go get github.com/<user>/<repo>.

The error message you saw comes from a new feature implemented in go get to support Go modules - you can now also specify the version of a dependency: go get github.com/<user>/<repo>@<version>, where version is a git tag using semver, e.g. v1.0.2.

Solution 3:

I met this issue, too. After some search, the following works by using go mod instead of go get, which is a feature of Golang Modules:

$ export GO111MODULE=on

$ go mod init <project name>

# go mod init HelloWorld
# or
# go mod init .

$ go mod download repo@version

# go mod download github.com/robfig/cron/[email protected]

Solution 4:

I got this error with Go v1.14 when running $ go get github.com/<user>/<repo>@<version> on an empty project before I had initialized my project with modules.

To resolve, I created a go.mod file using:

$ go mod init

I was able to rerun the get command successfully, which downloaded the vendor's package, updated the go.mod file, and created a go.sum file.