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 37 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:
As you already noticed, you should use go get .
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 , where version is a git tag using semver, e.g. v1.0.2.
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 I got this error with Go v1.14 when running $ go get 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.
If you get this error while you trying use modules, you should change dir to project before go get:
root@host:/# go get go: cannot use path@version syntax in GOPATH mode root@host:/# cd myproject/ root@host:/myproject# ls go.mod go.mod root@host:/myproject# go get go: finding github.com ff54c095001d81eed10615916a896512eb8d81ff go: finding ff54c095001d81eed10615916a896512eb8d81ff go: finding ff54c095001d81eed10615916a896512eb8d81ff go: finding ff54c095001d81eed10615916a896512eb8d81ff 1Update version of go following instructions at
This worked for me!
1Ran into this issue when i tried running the command in a directory outside of the directory where go mod is initialized. In order to download a module with a specific version go requires go.mod file which can keep track of multiple version of a same module. However trying to download the module in anywhere else outside of a go module directory(where GOPATH will be referenced to store the download module) will fail as there is no option to keep track of different versions of the same module.