使用Goenv命令设置Go的环境

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

使⽤Goenv命令设置Go的环境
前⾔
在进⾏Go开发的时候,设置Go的环境变量信息是必须的。

下⾯介绍windows和Linux,以及Go⾃⾝提供的命令进⾏设置的形式Linux的设置
In Linux or macOS, you can execute the below commands.(在Linux或者macOS,你可以执⾏下⾯的命令)
# Enable the go modules feature
export GO111MODULE=on
# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io
但是这种有个不好的地⽅,就是如果换⼀个终端或者重新开机,就没有了。

那么我推荐,在/etc/profile.d/这个⽂件夹下⾯,写⼀个
go.sh⽂件,把上⾯两句抄上就⾏。

当然,你也可以只给⾃⼰当前的登录⽤户使⽤,那就设置⾃⼰的profile的加载.
那就是这俩⽂件:.bashrc或者.bash_profile⽂件(Or, write it into the .bashrc or .bash_profile file.)
复制代码
Windlows设置
In Windows, you can execute the below commands.(在Windlows中,你可以执⾏下⾯的命令)
# Enable the go modules feature
$env:GO111MODULE="on"
# Set the GOPROXY environment variable
$env:GOPROXY="https://goproxy.io"
注意:不过我还是建议使⽤:我的电脑-->属性--->环境变量这种操作来进⾏配置
复制代码
Go version >= 1.13 当你的GO的版本⼤于1.13的时候
当你安装的GO的语⾔版本⼤于1.13的时候,那么就不⽤这么⿇烦了,直接使⽤go env -w命令就⾏了
go env -w GOPROXY=https://goproxy.io,direct
# Set environment variable allow bypassing the proxy for selected modules
go env -w GOPRIVATE=*
go env -w GO111MODULE=on
这个我试过,即使你关闭了终端,新打开,还是可以的,这个命令⽐较的⽆伤害.
但是,1.16.5 版本,⽤go env -w 也有不⽣效的时候。

相关文档
最新文档