Post

How to Install Go and Set Path for Global Accessibility in Linux

How to Install Go and Set Path for Global Accessibility in Linux

To install Go (Golang) and set up the environment so that tools like subfinder,nuclei etc. work properly, follow these step-by-step instructions.

✅ 1. Download and Install Go

🔹 For Linux / WSL / Kali:

1
2
3
4
5
6
7
8
# Remove any existing Go installation
sudo rm -rf /usr/local/go

# Download the latest version of Go (change version if needed)
wget https://go.dev/dl/go1.22.2.linux-amd64.tar.gz

# Extract it to /usr/local
sudo tar -C /usr/local -xzf go1.22.2.linux-amd64.tar.gz

✅ 2. Set Up Go Environment Variables

Edit your shell profile file:

If you use bash, edit:

1
nano ~/.bashrc

If you use zsh, edit:

1
nano ~/.zshrc

Add the following at the bottom:

1
2
3
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

Apply changes:

1
source ~/.bashrc  # or source ~/.zshrc

You can find out which shell you’re using with any of the following commands:

✅ Method 1: Check current shell in use

1
echo $SHELL
  • This shows your default login shell (e.g., /bin/bash, /bin/zsh).

✅ Method 2: Check your active shell process

1
ps -p $$
  • This shows the current shell process you’re actively using.
  • Output example:
    1
    2
    
    PID TTY          TIME CMD
    1234 pts/0    00:00:00 bash
    

    ✅ Method 3: Using echo $0

    1
    
    echo $0
    
  • It may return:
    • bash
    • zsh
    • sh (for minimal POSIX shell)
    • -bash (if it’s a login shell)

If you need to switch to bash or zsh, just run:

1
2
bash   # Switch to bash
zsh    # Switch to zsh (if installed)

✅ 3. Verify Installation

1
go version

Expected output:

1
go version go1.22.2 linux/amd64

It will be installed at:

1
~/go/bin/subfinder

So now you can just run:

1
subfinder -h

✅ 5. (Optional) Check Go Paths

1
2
echo $GOPATH
echo $PATH

You should see something like:

1
2
/home/youruser/go
...:/usr/local/go/bin:/home/youruser/go/bin

And that’s it for this article. Hope you like it.

Happy Learning and Keep Hacking.

This post is licensed under CC BY 4.0 by the author.