本指南是我在 Mac 機器上安裝 Golang 的方法。
您使用以下內容:
來自 asdf-golang
asdf plugin add golang https://github.com/asdf-community/asdf-golang.git # install latest golang version asdf install golang latest # set the glboal version for golang to latest asdf global golang latest # reshim asdf reshim golang
GOROOT 是指定 Go 安裝位置的環境變數
將以下內容加入~/.zshrc
. ~/.asdf/plugins/golang/set-env.zsh
這將確保每次運行終端時都設定 GOROOT 和 GOPATH
可以看看set-env.zsh做了什麼:
$ cat ~/.asdf/plugins/golang/set-env.zsh
asdf_update_golang_env() { local go_bin_path go_bin_path="$(asdf which go 2>/dev/null)" if [[ -n "${go_bin_path}" ]]; then export GOROOT GOROOT="$(dirname "$(dirname "${go_bin_path:A}")")" export GOPATH GOPATH="$(dirname "${GOROOT:A}")/packages" fi } autoload -U add-zsh-hook add-zsh-hook precmd asdf_update_golang_env
更新目前開啟的終端以使用最新的 ~/.zshrc
source ~/.zshrc
檢查GOROOT和GOPATH是否設定
> echo $GOROOT /Users/username/.asdf/installs/golang/1.22.5/go > echo $GOPATH /Users/username/.asdf/installs/golang/1.22.5/packages
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3