Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to install go in mac

Shulou Source: shulou.com Published: 2022-06-01 19:30:40 10月04日 Update

This article mainly shows you "how to install go in mac", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to install go in mac" this article.

Installation mode

Brew install go

Download the corresponding installation package on the official website and install it directly

Note:

In the first way, the go executable file is under / usr/local/bin. In fact, the go in this directory is a soft connection.

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

We found that this is actually linked to the go installation directory of brew install.

The second way to install is that the executable file of go is under / usr/local/go/bin, which is the default installation directory of go pkg package.

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

# goexport GOPATH=/Users/ljh/goexport GOBIN=$GOPATH/binexport PATH=$PATH:$GOBIN

At this point, run 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=" -GO2 "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 "

It is found that there is another GOROOT. Let's explain it.

Nouns explain GOROOTgo language installation directory GOPATH project workspaceGOBIN executable file directory, such as go install will generate executable files directly into the bin directory

GOPATH will also contain three directory nouns | explain-src | Source file pkg | compiled library files, mainly * .a files, for example, go install puts compiled ordinary packages into the pkg directory bin | executable directory, such as go install will generate executable files directly into the bin directory

Generally speaking, you have to add the go executable directory (${GOBIN}) to the PATH so that the GO command and the GO application we write can be called globally

So we have completed the installation of golang

The above is all the contents of the article "how to install go in mac". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Contents files interpretations contents methods articles three nouns learning help generation compilation general general global variables noun interpretation commands engineering engineering projects Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Redmi Shulou Tech Info Xiaomi macOS