go get下载包失败问题
source link: https://segmentfault.com/a/1190000039232866
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
由于某些不可抗力的原因,国内使用 go get
命令安装包时会经常会出现timeout的问题。本文介绍几个常用的解决办法。
从github克隆
golang在github上建立了一个镜像库,如 https://github.com/golang/net
就对应是 https://golang.org/x/net
的镜像库。 要下载 golang.org/x/net
包,可以在本地创建包的目录后使用 git clone
来拉取相应包的源代码文件,具体操作如下:
mkdir -p $GOPATH/src/golang.org/x cd $GOPATH/src/golang.org/x git clone https://github.com/golang/net.git
使用gopm
使用gopm可以从golang.org的一些镜像网站上下载。
安装gopm
go get -u github.com/gpmgo/gopm
使用gopm安装第三方包
不加 -g
参数,会把依赖包下载 .vendor
目录下面; 加上 -g
参数,可以把依赖包下载到 GOPATH
目录中。
gopm get -g golang.org/x/net
使用goproxy
Go的1.11版本以后 可以设置 GOPROXY
这个变量,来设置代理。 如果你自己有代理服务器就可以把这个环境变量设置成自己的代理。 首先开启 go module
支持:
在Mac/linux下执行:
export GO111MODULE=on
Windows平台执行:
SET GO111MODULE=on
2019.6.10更新: goproxy.cn
我们这里以 https://goproxy.cn
为例:
在Mac/linux下可以执行以下命令来设置:
export GOPROXY=https://goproxy.cn
Windows平台在 cmd
执行以下命令来设置:
SET GOPROXY="https://goproxy.cn"
或者在 PowerShell
中执行:
C:\> $env:GOPROXY = "https://goproxy.cn"
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK