1. 程式人生 > 程式設計 >使用Go env命令設定Go的環境

使用Go env命令設定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=*.corp.example.com
go env -w GO111MODULE=on


這個我試過,即使你關閉了終端,新開啟,還是可以的,這個命令比較的無傷害.
複製程式碼