共计 892 个字符,预计需要花费 3 分钟才能阅读完成。
Mac 零碎默认是不带 Go 软件包的,所以零碎比拟洁净。在 Mac 零碎上装置 Go,次要有上面几种办法:
- 应用压缩包解压装置
- 应用安装包间接装置
- 应用
Homebrew
装置 - 应用源码编译装置
本文以 Go 1.19
版本为例,应用官网软件包解压装置的办法,介绍如何在 Mac 零碎装置 Go 语言开发环境。
装置步骤
1. 下载 Go 软件包
到官方网站下载页面 https://golang.google.cn/dl/,下载go1.19.2.darwin-amd64.tar.gz
。
2. 解压
能够将 Go 软件包装置在任意目录,然而依据官网的倡议,咱们将其装置到 /usr/local/go
目录。
sudo tar -C /usr/local -xvzf go1.19.2.darwin-amd64.tar.gz
3. 配置
在 ~/.bash_profile
配置 GOROOT
和GOPATH
,其中 GOROOT
示意 Go 语言环境所在目录,GOPATH
示意我的项目的工作目录。
# Go 语言设置
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
家喻户晓的起因,Go 下载模块须要设置代理,具体设置办法能够参考:https://goproxy.cn/,上面两种形式都能够:
# 设置模块代理(办法一)export GO111MODULE=on
export GOPROXY=https://goproxy.cn
# 设置模块代理(办法二)go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
应用示例
示例:装置并运行教程《A Tour of GO》。
$ mkdir $HOME/go; cd $HOME/go
$ go install golang.org/x/website/[email protected]
$ tour
参考资料
- 官网下载:https://golang.google.cn/dl/
- Go 模块代理:https://goproxy.cn/
正文完