在Debian系統下管理Golang版本,推薦使用 Go Version Manager (GVM) 或 asdf。以下是使用這兩種工具的詳細步驟:
安裝GVM:
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
如果你使用的是zsh,將上述命令中的bash
替換為zsh
。
列出可用的Go版本:
gvm listall
安裝特定版本的Go:
gvm install go1.17.6
切換到已安裝的Go版本:
gvm use go1.17.6
卸載Go版本:
gvm uninstall go1.17.6
設置全局或局部版本:
gvm global go1.17.6
gvm local go1.16.5
安裝asdf:
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
source ~/.bashrc
安裝asdf的Golang插件:
asdf plugin-add golang https://github.com/asdf-vm/asdf-golang.git
添加Golang版本:
asdf install golang 1.17.6
asdf install golang 1.16.5
設置全局或局部版本:
asdf global golang 1.17.6
asdf local golang 1.16.5
更新包列表:
sudo apt update
安裝指定版本的Go:
sudo apt install golang-go1.11
驗證Golang是否已成功安裝:
go version