0
0
GoHow-ToBeginner · 3 min read

How to Install Go on Linux: Step-by-Step Guide

To install Go on Linux, download the latest .tar.gz archive from the official Go website, extract it to /usr/local, and add /usr/local/go/bin to your PATH. Then verify the installation by running go version in the terminal.
📐

Syntax

Here are the main commands to install Go on Linux:

  • wget: Downloads the Go archive from the official site.
  • tar -C /usr/local -xzf: Extracts the archive to /usr/local.
  • Update PATH: Adds Go binaries to your system path.
  • go version: Checks the installed Go version.
bash
wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
Output
go version go1.20.5 linux/amd64
💻

Example

This example shows how to download, install, and verify Go on a Linux system.

bash
wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

# Verify installation
go version
Output
go version go1.20.5 linux/amd64
⚠️

Common Pitfalls

Common mistakes when installing Go on Linux include:

  • Not removing older Go versions before installing a new one, which can cause conflicts.
  • Forgetting to add /usr/local/go/bin to the PATH, so the go command is not found.
  • Running export PATH=... only in the current terminal session instead of adding it to ~/.profile or ~/.bashrc for persistence.
bash
## Wrong: Not updating PATH persistently
export PATH=$PATH:/usr/local/go/bin
# This works only in current terminal

## Right: Add to ~/.profile or ~/.bashrc
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
source ~/.profile
📊

Quick Reference

Summary tips for installing Go on Linux:

  • Always download the latest stable version from https://go.dev/dl/.
  • Use sudo to extract Go to /usr/local for system-wide access.
  • Add Go binaries to your PATH permanently by editing your shell profile.
  • Verify installation with go version.

Key Takeaways

Download the latest Go archive from the official site for Linux.
Extract Go to /usr/local and add /usr/local/go/bin to your PATH.
Make PATH changes permanent by editing your shell profile file.
Verify installation by running go version in the terminal.
Remove old Go versions before installing a new one to avoid conflicts.