如何设置go环境变量GOPATH?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cnwyt/article/details/84962807

如何设置go环境变量GOPATH?

安装 gin-gonic/gin 报错: cannot download, $GOPATH not set. For more details see: go help gopath

$ go get -u github.com/gin-gonic/gin
package github.com/gin-gonic/gin: 
  cannot download, $GOPATH not set. 
For more details see: go help gopath

直接在终端输入echo $GOPATH,没有任何返回值。

手动设置 GOPATH 环境变量:

$ export GOPATH=$HOME/go

重新加载 ~/.bash_profile 环境变量配置:

$ source ~/.bash_profile 

如果是 Ubuntu, 可能需要重新加载的是 ~/.bashrc 文件:

$ source ~/.bashrc

再次查看 $GOPATH 环境变量,可以正常输出了。

$ echo $GOPATH 
/Users/wangtom/go

参考链接:

https://github.com/golang/go/wiki/SettingGOPATH

[END]

猜你喜欢

转载自blog.csdn.net/cnwyt/article/details/84962807