How to solve unrecognized import path error when doing go get with golang ?


When you want to download a golang dependency from a golang repository or from github repository, you would get this error:

go get -u          
go:[email protected]: unrecognized import path "": https fetch: Get "": dial tcp i/o timeout

The -u flag means:

The -u flag instructs get to update modules providing dependencies of packages named on the command line to use newer minor or patch releases when available. Continuing the previous example, ‘go get -u A’ will use the latest A with B v1.3.1 (not B v1.2.3). If B requires module C, but C does not provide any packages needed to build packages in A (not including tests), then C will not be updated.

Here we tried to download a prometheus library from golang, but we got unrecognized import path error.


You should specify the proxy before doing the go get job.

You should use this tag:

export GOPROXY=

What is a GOPROXY?

By default the go command downloads modules from VCS’s directly. The GOPROXY environment variable allows further control over the download source. The environment variable configures the go command to use a Go module proxy.

By setting the GOPROXY environment variable to a Go module proxy, you can overcome all of the disadvantages listed above:

  • The Go module proxy is by default caching and storing all the dependencies forever (in immutable storage). This means you don’t have to use any vendor/ folder anymore.

  • Getting rid of the vendor/ folder means your projects won’t take space in your repository. Because the dependencies are stored in immutable storage, even if a dependency disappears from the internet, you’re protected against it.
  • It’s not possible to override or delete a Go module once it’s stored in the Go proxy. This protects you against actors who might inject malicious code with the same version.
  • You don’t require any VSC tools anymore to download the dependencies because the dependencies are served over HTTP (Go proxy uses HTTP under the hood).
  • It’s significantly faster to download and build your Go module because Go proxy serves the source code (.zip archive) and go.mod independently over HTTP. This causes the downloads to take less time and faster (due to less overhead) compared to fetching from a VCS. Resolving dependencies is also faster because the go.mod can be fetched independently (whereas before it had to fetch the whole repository). The Go team tested it andthey saw a 3x speedup on fast networks and 6x on slow networks!
  • You can easily run your own Go proxy, which gives you more control over the stability of your build pipeline and protects against the rare cases when the VCS is down.

What is is A global proxy for Go modules, it is one of the world’s earliest Go modules mirror proxy services, developed and maintained by a group of young people who love open source and the Go language


You can setup your by using these commands:

For MAC/Linux Users:

# add environment to your profile
echo "export GOPROXY=" >> ~/.profile && source ~/.profile

# if your terminal is zsh,type the command below
echo "export GOPROXY=" >> ~/.zshrc && source ~/.zshrc

For Windows Users:

1. Right click This PC -> Properties -> Advanced system settings -> Environment Variables
2. Click "New" in Environment Variables
3. Input Variable Name: “GOPROXY”
4. Input Variable Value: “”
5. Click "OK", save your settings.

Run again

go get -u  

go: downloading v1.7.1
go: found in v1.7.1
go: downloading v0.1.3
go: downloading v0.10.0
go: downloading v1.4.2
go: downloading v1.0.1
go: downloading v2.1.1
go: downloading v0.2.0
go: downloading v0.0.0-20200615200032-f1bc736245b1
go: downloading v1.23.0
go: downloading v1.0.1
go: upgrade => v1.4.2
go: upgrade => v1.0.1
go: upgrade => v0.0.0-20200828194041-157a740278f4
go: upgrade => v0.1.3
go: upgrade => v0.13.0
go: upgrade => v0.2.0
go: upgrade => v1.25.0
go: downloading v0.0.0-20200828194041-157a740278f4
go: downloading v1.25.0
go: downloading v0.13.0

We complete the job successfully.