Mac Golang开发环境搭建

1. 安装go

手动方式

官网下载压缩包,然后配置GOROOT和PATH,笔者采用下边这种方式。

Homebrew方式

笔者在 macOS Catalina 版本0.15.1 (19B88) 下直接安装遇到点问题,如下:

// 考虑使用 install 直接搞定,结果各种超时
$ brew install go
Error: Net::OpenTimeout

// 参考 http://mirrors.ustc.edu.cn/help/homebrew-bottles.html 更换源,结果报错
$ brew install go
··· ···
Error: Xcode alone is not sufficient on Dunno.
Install the Command Line Tools:
  xcode-select --install

// 安装xcode-select,反馈已经安装
$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

// 尝试升级xcode-select,发现无需升级
$ softwareupdate --list
Software Update Tool

Finding available software
No new software available.

$ softwareupdate -i Command Line Tools
Software Update Tool

Command: No such update
Line: No such update
Tools: No such update
No updates are available.

// 最后怀疑brew版本问题,发现确实版本过低
$ brew --version
Homebrew 1.7.1
Homebrew/homebrew-core (git revision b0f2e; last commit 2019-11-17)

// 重新安装新版本
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew --version
Homebrew 2.1.16
Homebrew/homebrew-core (git revision b0f2e; last commit 2019-11-17)
Homebrew/homebrew-cask (no git repository)

// 再次安装,终于ok了
$ brew install go
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/go-1.13.4.catalina.bottle.tar.gz
######################################################################## 100.0%
==> Pouring go-1.13.4.catalina.bottle.tar.gz
  /usr/local/Cellar/go/1.13.4: 9,271 files, 414MB

$ go version
go version go1.13.4 darwin/amd64

你可能感兴趣的:(Mac Golang开发环境搭建)