- 安装homebrew
- 安装GO语言
brew update && brew upgrade
brew install go
- 创建GoPath文件夹
cd ~
mkdir bin src pkg
- 修改环境变量
cd ~
vim .bash_profile
export GOROOT=/usr/local/opt/go/libexec
export GOPATH=/Users/deweixu/coding/Go/go_path
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source .bash_profile
- 验证安装成功
```
go env
#############################################################
Last login: Thu May 17 11:14:43 on ttys000
JoeyTsaideMacBook-Pro:~ joeytsai$ brew update && brew upgrade
^CJoeyTsaideMacBook-Pro:~ joeytsai$ brew update && brew upgrade
^CJoeyTsaideMacBook-Pro:~ joeytsai$ brew install go
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 3 taps (homebrew/core, homebrew/services, caskroom/versions).
==> New Formulae
eccodes libbitcoin-protocol wireguard-go
fork-cleaner nifi-registry
==> Updated Formulae
unrar ✔ heroku paps
ace hesiod passenger
annie hopenpgp-tools pcb
aptly imagemagick pdal
archey imagemagick@6 pdsh
aria2 inetutils pegtl
armadillo ipfs perkeep
aws-sdk-cpp iso-codes petsc
awscli jenkins pgroonga
babeld jfrog-cli-go pidgin
babl jhiccup pilosa
bettercap jhipster pipenv
bitrise joplin poppler
cake kitchen-sync postgrest
cimg knot pound
citus kompose proguard
clojure kubernetes-cli proxytunnel
consul kubernetes-helm raine
curl libbi raylib
dartsim libbitcoin-client reminiscence
dash libbitcoin-explorer rocksdb
dbxml libbitcoin-server rsyslog
dcd libgphoto2 s-nail
debianutils libidn schismtracker
diamond libphonenumber shfmt
dnscrypt-proxy libpqxx skaffold
doitlive libqalculate skafos
dscanner libswiften skipfish
dxpy libu2f-host snakemake
elektra loudmouth snownews
ethereum lxc solr
faas-cli maxwell sops
fabio mcabber source-to-image
fabric mercurial spigot
fdroidserver meson spring-roo
feh metabase srtp
fn micropython stubby
folly mikutter tepl
freediameter mongodb@3.2 tippecanoe
fstrm mpc todoman
gandi.cli msgpack traefik
gauge nano twarc
gegl neomutt vtk
getdns node-build webpack
git-ftp node@8 winetricks
goenv nsd wireguard-tools
grafana open-mpi wtf
grpc osm2pgrouting xqilla
gtksourceview@4 osquery xsv
gx pam-u2f you-get
gx-go pandoc
==> Renamed Formulae
latexila -> gnome-latex
==> Downloading https://homebrew.bintray.com/bottles/go-1.10.2.high_sierra.bottl
######################################################################## 100.0%
==> Pouring go-1.10.2.high_sierra.bottle.tar.gz
==> 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.10.2: 8,161 files, 336.7MB
JoeyTsaideMacBook-Pro:~ joeytsai$ cd !
-bash: cd: !: No such file or directory
JoeyTsaideMacBook-Pro:~ joeytsai$ cd ~
JoeyTsaideMacBook-Pro:~ joeytsai$ mkdir ./gopath
JoeyTsaideMacBook-Pro:~ joeytsai$ cd gopath/
JoeyTsaideMacBook-Pro:gopath joeytsai$ ls
JoeyTsaideMacBook-Pro:gopath joeytsai$ mkdir bin src pkg
JoeyTsaideMacBook-Pro:gopath joeytsai$ ls
bin pkg src
JoeyTsaideMacBook-Pro:gopath joeytsai$ $ brew update && brew upgrade
-bash: $: command not found
JoeyTsaideMacBook-Pro:gopath joeytsai$ $ brew install go
-bash: $: command not found
JoeyTsaideMacBook-Pro:gopath joeytsai$ vim .bash_profile
JoeyTsaideMacBook-Pro:gopath joeytsai$ cd ~
JoeyTsaideMacBook-Pro:~ joeytsai$ vim .bash_profile
JoeyTsaideMacBook-Pro:~ joeytsai$ source .bash_profile
JoeyTsaideMacBook-Pro:~ joeytsai$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/joeytsai/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
JoeyTsaideMacBook-Pro:~ joeytsai$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/joeytsai/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/deweixu/coding/Go/go_path"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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/cm/f8h7wfls1hbdmlbbq19w_qb40000gn/T/go-build988668711=/tmp/go-build -gno-record-gcc-switches -fno-common"
JoeyTsaideMacBook-Pro:~ joeytsai$
#############################################################
```