preface

Setting environment variable information for Go is a must during Go development. Here are the Settings for Windows and Linux, as well as the commands provided by Go itself

Linux Settings

In Linux or macOS, you can execute the below commands.

# Enable the go modules feature
export GO111MODULE=on
# Set the GOPROXY environment variable
exportGOPROXY=https://goproxy.io But this has a bad place, is if you change a terminal or restart, there is no. In /etc/profile.d/, write a go.sh file and copy the above two sentences. Of course, you can only use your current logged-in users by setting up your own profile load. Bashrc Or.bash_profile file (Or, write it into the.bashrc Or.bash_profile file.)Copy the code

Windlows set

In Windows, you can execute the below commands. In Windows, you can execute the below commands.

# Enable the go modules feature
$env:GO111MODULE="on"
# Set the GOPROXY environment variable
$env:GOPROXY="https://goproxy.io"Note: HOWEVER, I recommend using my Computer > Properties > Environment Variables for configurationCopy the code

Go version >= 1.13 When your Go version is greater than 1.13

If you have installed GO older than 1.13, don’t bother and just use GO env -w

go env -w GOPROXY=https://goproxy.io,direct
# Set environment variable allow bypassing the proxy for selected modulesGo env -w GOPRIVATE=*.corp.example.com go env -w GO111MODULE=onCopy the code