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

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


go 菜鸟教程

环境安装

mac 环境 首先安装brew

    brew install go

执行完命令后,如下显示:

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/services).
No changes to formulae.

==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/go-1.11.2.m
######################################################################## 100.0%
==> Pouring go-1.11.2.mojave.bottle.tar.gz
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall go`
==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
  https://golang.org/doc/code.html#GOPATH

You may wish to add the GOROOT-based install location to your PATH:
  export PATH=$PATH:/usr/local/opt/go/libexec/bin
==> Summary
🍺  /usr/local/Cellar/go/1.11.2: 9,282 files, 404MB

需要设置GOPATH和GOROOT的环境变量,以及设置PATH.

环境变量配置

通过go env查看go的详细信息

go env

需要设置的环境变量包括:GOPATH ,GOBIN 以及把GOBIN加入到PATH中,GOROOT变量默认已经设置好。

如果需要修改默认的环境变量配置修改 vim ~/.bash_profile 或者 vim ~/.zshrc

#GOROOT
# CentOS 中如下设置 GOROOT,看你安装的路径
# export GOROOT=/usr/local/go
# Mac OS 中通过命令行工具brew安装如下配置 GOROOT
export GOROOT=/usr/local/opt/go/libexec
#GOPATH ro
评论 29
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值