Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

go

gopath

I'm unable to run go get git@github<user/repo> in my $GOPATH folder. Getting this error:

go: cannot use path@version syntax in GOPATH mode

I just want to understand why go get isn't working even though $GOPATH is configured during the installation. Environment is ubuntu.

~/$ echo $GOPATH
/home/user/go
like image 322
zero Avatar asked Jan 29 '19 07:01

zero


4 Answers

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

like image 116
emaxi Avatar answered Oct 17 '22 10:10

emaxi


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.

like image 28
rob74 Avatar answered Oct 17 '22 10:10

rob74


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]
like image 21
cz.ycaptain Avatar answered Oct 17 '22 11:10

cz.ycaptain


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.

like image 9
Feckmore Avatar answered Oct 17 '22 10:10

Feckmore