If you have Homebrew installed, you can easily install Go with these commands:
# Install Git (if you don't have it)brew install git# Install Gobrew install go# Add GOBIN path to your PATH in ~/.bash_profile or ~/.zshrcexport PATH=${HOME}/go/bin:$PATH
You can download Go in two ways:Option 1: From the web
firefox https://golang.org/dl
Select Linux and download the tar.gz file.Option 2: Using snap (skip to step 4 if you use this)
sudo snap install go --classic
3
Extract Go to /usr/local
Find the downloaded file name and extract it:
# Replace 'goX.XX.X.linux-amd64.tar.gz' with your downloaded filesudo tar -C /usr/local -xzf ~/Downloads/go*.linux-amd64.tar.gz
4
Add Go to PATH
Add Go executables to your PATH:
# Add Go binary directoryecho 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile# Add your Go workspace bin directoryecho 'export PATH=$PATH:$HOME/go/bin' >> ~/.profile# Reload your profilesource ~/.profile
5
Install Go Tools
Install helpful development tools:
go install golang.org/x/tools/...@latest
This creates a ~/go directory where Go tools and your projects will live (when not using Go modules).
6
Install VS Code (Optional)
Open “Ubuntu Software” application
Search for “Visual Studio Code”
Click Install
Then install the Go extension from the VS Code extensions marketplace.
7
Verify Installation
go version
You should see output like: go version go1.x.x linux/amd64