g
特性
- 支持列出可供安装的 go 版本号
- 支持列出已安装的 go 版本号
- 支持在本地安装多个 go 版本
- 支持卸载已安装的 go 版本
- 支持在已安装的 go 版本之间自由切换
- 支持软件自我更新(>= 1.3.0)
安装
自动化安装
Linux/macOS(适用于bash、zsh)
# 建议安装前清空`GOROOT`、`GOBIN`等环境变量
$ curl -sSL https://raw.githubusercontent.com/voidint/g/master/install.sh | bash
$ echo "unalias g" >> ~/.bashrc # 可选。若其他程序(如'git')使用了'g'作为别名。
$ source ~/.bashrc # 或者 source ~/.zshrc
手动安装
下载release的二进制压缩包
PATH/usr/local/bin
~/.bashrc~/.zshrc
$ cat>>~/.bashrc<<'EOF'
export GOROOT="${HOME}/.g/go"
export PATH="${HOME}/.g/go/bin:$PATH"
export G_MIRROR=https://golang.google.cn/dl/
EOF
启用环境变量
$ source ~/.bashrc # 或source ~/.zshrc
使用
stable
国内需要先设置环境变量,否则可能无法使用 export G_MIRROR=https://studygolang.com/dl
$ g ls-remote stable 1.13.15 1.14.7
1.14.7
$ g install 1.14.7 Downloading 100% |███████████████| (119/119 MB, 9.939 MB/s) [12s:0s] Computing checksum with SHA256 Checksums matched Now using go1.14.7
查询已安装的go版本
$ g ls 1.7.6 1.11.13 1.12.17 1.13.15 1.14.6 * 1.14.7
查询可供安装的所有go版本
$ g ls-remote 1 1.2.2 1.3 1.3.1 ... // 省略若干版本 1.14.5 1.14.6 * 1.14.7 1.15rc1
切换到另一个已安装的go版本
$ g use 1.14.6 go version go1.14.6 darwin/amd64
卸载一个已安装的go版本
$ g uninstall 1.14.7 Uninstalled go1.14.7
更新 g 软件本身
$ g update A new version of g(v1.2.2) is available Downloading 100% |███████████████| (3.7/3.7 MB, 2.358 MB/s) Computing checksum with SHA256 Checksums matched Update completed
FAQ
G_MIRRORG_EXPERIMENTALtrueG_HOME~/.gG_EXPERIMENTAL=trueHTTP_PROXYHTTPS_PROXYhttp_proxyhttps_proxyg符号链接Windows Vista$Path$Pathpath.ps1