GO language sdk download, installation and configuration


  1. Download go windows from the official website :
    The go download link
    is as follows. After clicking in, you should see this interface. You can directly click on the .msi file corresponding to the system version, which makes installation and uninstallation easy. Another way is to download the compressed package, unzip it where you like, and then configure the environment variables.
    Insert image description here
    centos7
    has a corresponding yum in centos7, which can save a lot of effort. Just do it directly
yum install golang

That’s
2. Configure environment variables.
The command to view go’s environment variables is as follows:

go env
#结果如下:
set GO111MODULE=off
set GOARCH=amd64
set GOBIN=E:\go course\bin
set GOCACHE=E:\go course\go-build
set GOENV=C:\Users\samu\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\go course\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\go course
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=E:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=E:\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.5
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\samu\AppData\Local\Temp\go-build382283171=/tmp/go-build -gno-record-gcc-switches

GOROOT
Golang's installation directory, the installation location of built-in programs
GOPATH
is mostly considered to be the working directory, which should contain three directories: src, bin and pkg. src holds the source library files downloaded by go get, which has the same effect as git clone; bin After saving the go install command, the installed executable program; pkg is an archive file of the project code, ending with .a, which is similar to the pkg directory in go. The reason why most people think of it as the working directory is that in addition to downloading, we can also generate tokens for calling. You can refer to: The
section about packages in the go tutorial on the go language Chinese website
. The GOBIN
compiled binary code storage location.
GO111MODULE
is related to go module. We can first set this variable to off (i.e. off).
Everyone should know about configuring environment variables, right?
In win10, right-click [Computer] to open [Properties], and configure it in [Environment Variables]. If you installed it by decompression, you need to configure the location of go.exe in the bin directory under your go installation directory in Path, and configure Okay, even if it is installed.
centos7:

export PATH=$PATH:[具体目录]#对既有环境变量PATH进行配置
export GOPATH=[具体目录]#配置新变量

In addition, you can also use go internal command settings to set go environment variables.

go env -w GOPROXY=http://mirrors.aliyun.com/goproxy/
#这个命令就将GOPROXY变量覆盖成了阿里云,让go run或者go build更快
  1. Regarding pitfalls:
    When you go env, you can set [environment variable]=[directory], but this is not written into the configuration. You still need to configure variables such as GOPATH and GOROOT yourself. In fact, you can switch to the corresponding ones in your source files. You can go run the directory, which is enough for daily learning.
    Also, when you set up GOPATH and GOBIN, if you directly go build the file in your src directory, two results will be generated, one in the bin directory under your GOPATH path, and one in the current directory of your cmd. This is Debug and Release. The difference is that the executable file generated in your src directory may crash (click to run), but it can run under cmd. I am still checking the information on this issue, and I hope someone can give me some advice.

Guess you like

Origin blog.csdn.net/weixin_44948269/article/details/118223447