mac安装go环境

Posted php-linux

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mac安装go环境相关的知识,希望对你有一定的参考价值。

https://golang.google.cn/dl/
 

sudo vim /etc/profile

11 export GOROOT=/usr/local/go

 12 export GOPATH=${GOROOT}/gopath

 13 export PATH=$PATH:${GOROOT}/bin

 14 export GO111MODULE=on

 15 export GOPROXY=https://goproxy.cn

 

source /etc/profile 

说明:
1. GOROOT 为go安装目录, 在mac下使用pkg包安装的, 目录为 /usr/loca/go

 

如果用go mod gopath 设置为/usr/local/go/gopath 

 

查看环境 

go env 

macdeMacBook-Pro:www mac$ go env 
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mac/Library/Caches/go-build"
GOENV="/Users/mac/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mac/Desktop/go_learn"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/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/fc/4txmmczj6q92p6058h3w7t_80000gn/T/go-build984019761=/tmp/go-build -gno-record-gcc-switches -fno-common"

 

cd /Users/mac/Desktop/go_learn

macdeMacBook-Pro:go_learn mac$ go mod init brady

go: creating new go.mod: module brady

macdeMacBook-Pro:go_learn mac$ export GO111MODULE=on

 

以上是关于mac安装go环境的主要内容,如果未能解决你的问题,请参考以下文章

Go语言环境安装-Mac

Mac下golang环境安装以及新手入门

mac安装go环境

mac安装go环境

mac下安装配置go开发环境

MAC配置VSCODE的GO开发环境