编程知识 cdmana.com

[go Series 1] go installation (MAC)

Because the previous project depended on k8s, And with the k8s More integration of , and k8s The source code of is go Written , There was a lot of searching on the Internet about go Information about ,
It is found that many cloud native projects are created by go Written , So here we go again go Language , Because I used brew install mac Installed go, Also used. pkg Package installed go, So the environment is messy enough , thus , I want to clean it up

Installation mode

  1. brew install go
  2. Official website Download the corresponding installation package , Direct installation

Be careful :
The first way to install ,go The executable is in /usr/local/bin Next , In fact, under this catalog go It's a soft connection ,

*  bin ll /usr/local/bin |grep go
lrwxr-xr-x  1 ljh   admin      26  9 28 10:46 go -> ../Cellar/go/1.15.2/bin/go
lrwxr-xr-x  1 ljh   admin      29  9 28 10:46 godoc -> ../Cellar/go/1.15.2/bin/godoc
lrwxr-xr-x  1 ljh   admin      29  9 28 10:46 gofmt -> ../Cellar/go/1.15.2/bin/gofmt

We found that this is actually a link to brew install Of go Under the installation directory of

The second way to install ,go The executable file of is in /usr/local/go/bin Next , This is go pkg Package default installation directory

But no matter how you install it , All have to be configured GOPATH/GOBIN/PATH, as follows , These three variables will be explained later

#go
export GOPATH=/Users/ljh/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

This is the time , function go env

GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/ljh/go/bin"
GOCACHE="/Users/ljh/Library/Caches/go-build"
GOENV="/Users/ljh/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ljh/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ljh/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1l/mwvs7rf563x72kqcv7l6rb840000gn/T/go-build705548469=/tmp/go-build -gno-record-gcc-switches -fno-common"

I found another one GOROOT, Now let's explain

Noun explain
GOROOT go Language installation directory
GOPATH The project workspace
GOBIN Executable Directory , Such as go install Will generate an executable file and put it directly into bin Under the table of contents

and GOPATH There will also be three directories Noun | explain ---|--- src| Source file pkg| Compiled library files , Mainly *.a file , Such as go install Put the compiled ordinary package into the pkg Under the table of contents bin| Executable Directory , Such as go install Will generate an executable file and put it directly into bin Under the table of contents

Generally speaking , Must win go Executable Directory (${GOBIN}) Join in PATH in , send GO The command and what we wrote GO Applications can call ,
So we're done golang Installed.

版权声明
本文为[monkeyboy_ tech]所创,转载请带上原文链接,感谢

Scroll to Top