AdSense

網頁

2024/2/19

Mac 安裝Go版本管理工具gvm

Mac安裝Go語言的版本管理工具gvm(Go Version Manager)的方式如下。


環境

  • MacBook Pro Apple M1 Pro
  • macOS Ventura 13.0.1


安裝

先執行以下命令。

xcode-select --install
brew update
brew install mercurial

執行bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)安裝。命令列Shell是Zsh一樣也是執行此命令。

% bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Cloning from https://github.com/moovweb/gvm.git to /Users/user/.gvm
macOS detected. User shell is: /bin/zsh
Created profile for existing install of Go at '/opt/homebrew/Cellar/go/1.21.5/libexec'
Installed GVM v1.0.22

Please restart your terminal session or to get started right away run
 `source /Users/user/.gvm/scripts/gvm`

執行source /Users/user/.gvm/scripts/gvm更新當前terminal環境變數。

輸入gvm version出現版本資訊代表安裝成功。

gvm version
Go Version Manager v1.0.22 installed at /Users/user/.gvm


使用

輸入gvm listall可列出所有可安裝版本tag,例如go1.21.7

% gvm listall

gvm gos (available)

   go1
   go1.0.1
   go1.0.2
   go1.0.3
   go1.1
   ...
   go1.21.7
   go1.22rc1
   go1.22rc2
   go1.22.0
   ...

輸入gvm install [tag]安裝指定tag版本,例如gvm install go1.21.7

gvm install go1.21.7
Downloading Go source...
Installing go1.21.7...
 * Compiling...
go1.21.7 successfully installed!

輸入gvm list列出已安裝版本。

% gvm list

gvm gos (installed)

   go1.21.7
   system


輸入gvm use [tag]使用指定版本,例如gvm use go1.21.7

% gvm use go1.21.7
Now using version go1.21.7

沒有留言:

AdSense