[Solved] Getting GOPATH error “go: cannot use [email protected] syntax in GOPATH mode”

Let’s keep it simple recently, I tried to install one package using golang and got an error message claiming that golang can’t load the package, as shown below.

can't load package: package github.com/mypackage/[email protected]: cannot use [email protected] syntax in GOPATH mode

Multiple things, in theory, can generate this error requiring different solutions. Today I will provide you with two solutions to solve this error by yourself.

Solution 1: Switching Commands

In most scenarios, you may be using a install command to install the package in golang on your system. If you check the golang history before the install command, there was a get command [deprecated] to install and compile the packages.

Pros and Cons of Using React Native for Mobile Development

Below is the command that generates the error for me while installing the package.

$ go install -v github.com/mypackage/[email protected]

The error is thrown due to the install command, although I just changed the install into get command and tada, the problem was solved.

$ go get -v github.com/mypackage/[email protected]

Note: Although the problem has been solved but do not forget to consider that get command is deprecated and not supported any longer. I strongly recommend to use it in rare situation.

Solution 2: Go-Mode

Go-Mode covers the basic features you need while working with golang with other additional features such as autocomplete, analysis and refactoring. You can initiate a new project in Go-Mode and install the package using the mod download command as shown below.

How to fix VMware could not connect ‘Ethernet 0’ to virtual network ‘/dev/vmnet8’

First, export Go-Mode in your current terminal session as shown below.

$ export GO111MODULE=on

Next, we need to initiate a new project name. Consider this name as your package name.

$ go mod init <Project Name>

Finally, specify the package address along with the mod download command as shown below.

$ go mod download github.com/mypackage/[email protected]

And here we did our final step, mostly this will resolve your issue for “can’t load package”.

Final Thought

If any of the above solutions didn’t work out, please let us know in the comment section, and if you follow different steps to solve the above issue, then let us know so we can include it in this article.

Leave a Reply