1 前言
在進行Go開發的時候,設置Go的環境變量信息是必須的。下面介紹windows和Linux,以及Go自身提供的命令進行設置的形式
2 設置
2.1 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.)
2.2 Windows設置
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=*.corp.example.com go env -w GO111MODULE=on
這個我試過,即使你關閉了終端,新打開,還是可以的,這個命令比較的無傷害.
3 國內代理
阿里雲的goproxy:
http://mirrors.aliyun.com/goproxy/
待補充...
4 參考
1.https://studygolang.com/articles/24448?fr=sidebar
