gvm on macOS installation cheatsheet

OSX $PATH 設定路徑

1
2
3
4
5
6
7
8
9
10
# ~/.profile
# ~/.bash_profile
# ~/.bashrc
# ~/.zshrc

# /etc/profile
# /etc/paths
# /etc/paths.d

$ /usr/libexec/path_helper -s

移除 OSX 官方 go 安裝檔

1
2
3
4
5
# https://golang.org/doc/install#uninstall
$ rm /usr/local/go
$ rm /etc/paths.d/go

# 使用 gvm https://github.com/moovweb/gvm

查詢環境

1
$ go env

安裝

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# gvm
$ bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
# OR
$ zsh < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
# 重啓終端機

# 列出所有版本
$ gvm listall

# 列出本地版本
$ gvm list

# OSX 環境有問題的話
$ xcode-select --install
$ brew update
$ brew install mercurial

# 重新編譯(Compile)特定版本,需要先安裝好 Go1.4
$ gvm install <version>

# 直接安裝 Binary,不需要編譯
$ gvm install <version> -B

# 刪除 gvm
$ gvm implode
Are you sure? [Y/n] y
GVM successfully removed
# 或者
$ rm -rf ~/.gvm

# 2018-12-06 - Fix Compile Error: failed MSpanList_Insert & Missing go1.4
$ gvm install go1.7.3 -B
$ gvm use go1.7.3
$ gvm install go1.11.2
$ gvm use go1.11.2 --default

# 編輯 zshrc
[[ -s "/Users/andyyou/.gvm/scripts/gvm" ]] && source "/Users/andyyou/.gvm/scripts/gvm"
# export GOPATH=~/Projects/go
# gvm 預設 GOPATH
# ~/.gvm/pkgsets/go<version>/global
export PATH=$PATH:$(go env GOPATH)/bin

gvm on macOS installation cheatsheet

https://andyyou.github.io/2019/04/14/gvm-cheat-sheet/

作者

andyyou(YOU,ZONGYAN)

發表於

2019-04-14

更新於

2023-12-05

許可協議