Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crcastle/9878b50c246cd88a51a04288cc644d75 to your computer and use it in GitHub Desktop.
Save crcastle/9878b50c246cd88a51a04288cc644d75 to your computer and use it in GitHub Desktop.
Install Go using asdf on macOS

Install Go using asdf for Visual Studio Code on macOS

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 asdf

Don'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.2

Set the version that we just installed as Global:

asdf global golang 1.20.2

Create links to use the go command without any suffix on Terminal:

asdf reshim golang 1.20.2

Create Go package and source folder

mkdir -p ~/go/{bin,pkg,src}

If you get an error message, remove the folder with this command:

sudo rm -rf ~/go

Re-run the command above to create package and source folders. Note: You have to run it as sudo because Go changes this folder permissions.

Add GOROOT to your shell config file:

Add this line to your shell config file:

ZSH users: file is located at ~/.zshrc Bash users: file is located at ~/.zshrc

export GOROOT=~/.asdf/installs/golang/1.20.2/go

Reload your config file.

If you're using ZSH run this command on Terminal:

source ~/.zshrc

If you're using Bash run this command on Terminal:

source ~/.bashrc

Add these lines to your Visual Studio Code User Settings (bash):

Press 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/",

Install Go extension on Visual Studio Code

Open this URL and hit Install.

Install Go Tools

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment