问题
sudo go get github.com/tsenart/vegeta
# Error
package github.com/tsenart/vegeta: cannot download, $GOPATH not set. For more details see: go help gopath
根源
# ~/.bashrc
╭─xiaojia@xiaojia-Lenovo-G460 ~
╰─$ go env
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/xiaojia/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
# /etc/profile
╭─xiaojia@xiaojia-Lenovo-G460 ~
╰─$ sudo go env
[sudo] password for xiaojia:
GOARCH="amd64"
GOBIN="" ### not set
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="" ### not set
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
xubuntu这样配置是好的,至于ubuntu为什么会这样,目前仍没有解决该问题,只好先用临时方案:sudo -E go env
,用-E参数强制使用当前用户环境变量。
参考链接: 详细配置
有疑问加站长微信联系(非本文作者)