If you’re looking to get started with Go (also known as Golang) on a Linux system, you’re in the right place. Go is a fast, statically typed language made by Google, popular for its simplicity and performance. Here’s how to install it quickly and correctly.
Step 1: Check If Go Is Already Installed
Open your terminal and type:
go version
If you see something like go version go1.xx.x
, it’s already installed. If not, keep reading.
Step 2: Download the Latest Go Version
Head to the official Go downloads page:
Find the latest version for Linux and copy the link for the .tar.gz
file. Or you can download it with wget
like this:
wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz
(Replace the version number with the latest one from the site.)
Step 3: Remove Any Old Go Versions (Optional)
If you’ve installed Go before manually, remove it first:
sudo rm -rf /usr/local/go
Step 4: Install Go
Extract the downloaded archive to /usr/local
:
sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz
Step 5: Set Up Your Environment
Add Go to your PATH
. Open or create the file ~/.profile
, ~/.bashrc
, or ~/.zshrc
(depending on your shell), and add this line:
export PATH=$PATH:/usr/local/go/bin
Then reload your shell:
source ~/.profile
or
source ~/.bashrc
Step 6: Verify Installation
Run:
go version
You should see the version you installed. Now Go is ready to use!
Optional: Set Up Your Go Workspace
By default, Go uses ~/go
as your workspace. You can change it by adding this to your profile file:
export GOPATH=$HOME/my-go-projects
export PATH=$PATH:$GOPATH/bin
That’s It
You’ve got Go running on your Linux machine. From here, you can start building Go apps, test out packages, or dive into writing your own CLI tools.
Have questions or run into issues? Drop a comment below.
Leave a Reply