
This guide is what I did to get Golang setup on my Mac machine.
You use the following:
From 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 is the environment variable that specifics the location of the Go installation
Add the following to ~/.zshrc
. ~/.asdf/plugins/golang/set-env.zsh
This will ensure that GOROOT and GOPATH is set each time you run your terminal
You can see what set-env.zsh does:
$ 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
Update your currently opened terminal to use latest ~/.zshrc
source ~/.zshrc
Check to see if GOROOT and GOPATH is set
> echo $GOROOT /Users/username/.asdf/installs/golang/1.22.5/go > echo $GOPATH /Users/username/.asdf/installs/golang/1.22.5/packages
The above is the detailed content of Installing Golang on MacOS. For more information, please follow other related articles on the PHP Chinese website!
What are the front-end mvvm frameworks?
What are the enterprise erp systems?
How to solve waiting for device
Merge cell fill sequence number
What should I do if the docker container cannot access the external network?
Summary of common socket errors
jdk environment variable configuration
Yiooke wallet address