本指南是我在 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