Install Go language on Linux Use Command in Go

List Topics
February 15, 2025
No Comments
2 min read

To install Go (Golang) on Linux, follow these steps:

1. Check if Go is Already Installed

Bash
go version

If Go is installed, you'll see the version number. If not, proceed with the installation.

2. Download the Latest Go Version

Get the latest Go binary package from the official website:

Bash
wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz

Tip: Check the latest version at Go Downloads before running the command.

3. Remove Old Go Installation (if any)

Bash
sudo rm -rf /usr/local/go

4. Extract and Install Go

Bash
sudo tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz

5. Set Up Environment Variables

Add Go to your PATH by editing ~/.bashrc or ~/.profile:

Bash
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc

For Zsh users:

Bash
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.zshrc
echo 'export GOPATH=$HOME/go' >> ~/.zshrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.zshrc
source ~/.zshrc

6. Verify the Installation

Bash
go version

You should see output like:

Bash
go version go1.22.0 linux/amd64

7. Test Go with a Simple Program

Create a test file:

Bash
mkdir -p ~/go/src/hello
cd ~/go/src/hello
nano hello.go

Paste this code:

Bash
package main

import "fmt"

func main() {
    fmt.Println("Hello, Go!")
}

Run the program:

Bash
go run hello.go

You should see:

Bash
Hello, Go!
©2025 Linux Bangla | Developed & Maintaind by Linux Bangla.