使用Go env命令设置Go的环境
<h2 class="heading" data-id="heading-0">1 前言</h2><p>在进行Go开发的时候,设置Go的环境变量信息是必须的。下面介绍windows和Linux,以及Go自身提供的命令进行设置的形式</p>
<h2 class="heading" data-id="heading-1">2 设置</h2>
<h2 class="heading" data-id="heading-1">2.1 Linux的设置</h2>
<p><strong>In Linux or macOS, you can execute the below commands.(在Linux或者macOS,你可以执行下面的命令)</strong></p>
<div class="cnblogs_Highlighter">
<pre class="brush:bash;gutter:true;"># Enable the go modules feature
export GO111MODULE=on
# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io</pre>
</div>
<pre><code class="hljs bash copyable" lang="bash"><span class="hljs-comment"><span class="hljs-built_in"><span class="hljs-comment"><span class="hljs-built_in">但是这种有个不好的地方,就是如果换一个终端或者重新开机,就没有了。那么我推荐,在/etc/profile.d/这个文件夹下面,写一个 go.sh文件,把上面两句抄上就行。当然,你也可以只给自己当前的登录用户使用,那就设置自己的profile的加载. 那就是这俩文件:.bashrc或者.bash_profile文件(Or, write it into the .bashrc or .bash_profile file.) <span class="copy-code-btn"><br></span></span></span></span></span></code></pre>
<h2 class="heading" data-id="heading-2">2.2 Windows设置</h2>
<p><strong>In Windows, you can execute the below commands.(在Windlows中,你可以执行下面的命令)</strong></p>
<div class="cnblogs_Highlighter">
<pre class="brush:bash;gutter:true;"># Enable the go modules feature
$env:GO111MODULE="on"
# Set the GOPROXY environment variable
$env:GOPROXY="https://goproxy.io"</pre>
</div>
<pre><code class="hljs bash copyable" lang="bash"><span class="hljs-comment"><span class="hljs-variable"><span class="hljs-string"><span class="hljs-comment"><span class="hljs-variable"><span class="hljs-string">注意:不过我还是建议使用:我的电脑-->属性--->环境变量 这种操作来进行配置 <span class="copy-code-btn"><br></span></span></span></span></span></span></span></code></pre>
<h2 class="heading" data-id="heading-3">Go version >= 1.13 当你的GO的版本大于1.13的时候</h2>
<p><strong>当你安装的GO的语言版本大于1.13的时候,那么就不用这么麻烦了,直接使用go env -w命令就行了</strong></p>
<div class="cnblogs_Highlighter">
<pre class="brush:bash;gutter:true;">go env -w GOPROXY=https://goproxy.io,direct
# Set environment variable allow bypassing the proxy for selected modules
go env -w GOPRIVATE=*.corp.example.com
go env -w GO111MODULE=on</pre>
</div>
<pre><code class="hljs bash copyable" lang="bash"><span class="hljs-comment">这个我试过,即使你关闭了终端,新打开,还是可以的,这个命令比较的无伤害. <br><span style="font-size: 18px"><strong><br></strong></span></span></code></pre>
<h2 class="heading" data-id="heading-3">3 国内代理</h2>
<pre><code class="hljs bash copyable" lang="bash"><span class="hljs-comment"><span class="copy-code-btn">阿里云的goproxy:<br>http://mirrors.aliyun.com/goproxy/<br>待补充...<br><br></span></span></code></pre>
<h2 class="heading" data-id="heading-3">4 参考</h2>
<pre><code class="hljs bash copyable" lang="bash"><span class="hljs-comment"><span class="copy-code-btn">1.https://studygolang.com/articles/24448?fr=sidebar</span></span></code></pre><br><br>
来源:https://www.cnblogs.com/fanbi/p/13649929.html
頁:
[1]