I had a lot of issues trying to install Golang on macOS using asdf package manager to develop on Visual Studio Code.
So here's the steps needed to setup it properly:
Open Terminal and install asdf with this command:
You have to install Homebrew before running the installation command.
brew install asdfDon't forget to setup asdf on your shell by following asdf documentation.
After it finishes, it's time to install Go:
asdf install go 1.20.2asdf global golang 1.20.2asdf reshim golang 1.20.2mkdir -p ~/go/{bin,pkg,src}If you get an error message, remove the folder with this command:
sudo rm -rf ~/goRe-run the command above to create package and source folders. Note: You have to run it as
sudobecause Go changes this folder permissions.
Add this line to your shell config file:
ZSH users: file is located at
~/.zshrcBash users: file is located at~/.zshrc
export GOROOT=~/.asdf/installs/golang/1.20.2/goIf you're using ZSH run this command on Terminal:
source ~/.zshrcIf you're using Bash run this command on Terminal:
source ~/.bashrcPress Ctrl(Cmd) + Shift + P type User Settings bash and hit ENTER.
On this window paste the code down below and don't forget to Save:
"go.toolsGopath": "~/go/",
"go.gopath": "~/go/",Open this URL and hit Install.
Press Ctrl(Cmd) + Shift + P type go install tools and hit ENTER.
After you get a message like:
All tools successfully installed. You are ready to Go. :)
Reopen Visual Studio Code and everything should be working flawlessly.
To @therealvio's point about not hardcoding relative paths in shell configs, this is what I've got in mine and it appears to do the thing:
Appreciate the hot tip for
settings.jsonpointed at the~/godirectory. Mine looks like this now:{ "go.toolsGopath": "~/go/", "go.gopath": "~/go/", "go.testTimeout": "180s", "go.toolsEnvVars": { "GOPROXY": "https://proxy.golang.org,direct" } }