This blog is NOT OFFICIAL website of Kali Linux. We just share Tutorials to learn Cybersecurity.

How to Install Golang in Linux [New 2023 Method]

Home
Golang or Go is a new generation programming language many new tools like Modlishka, Gobuster and more comes written in Golang. Now Golang didn't comes pre-installed with our Kali Linux machine. In this detailed article we learn how to install Golang in Kali Linux in 2020.

There is two ways to install Golang in Linux system.
  1. From the Repository (If Go available in repo).
  2. Manual Install (Works always) .

install golang in Kali Linux

Installing Golang from repository

Previously we need to install Golang manually but now Golang is on Kali Linux's repository to install it we need to run following command:
sudo apt-get install -y golang
The installation process will took some time depending on internet speed and processing power of our machine.

Installing Golang from repository
Installing Golang from repository

Configure

After the installation process is done we need to configure a little bit in our .bashrc file. We open the .bashrc file by using following command:
sudo mousepad ~/.bashrc
Then we paste these following paths at the end of .bashrc file

# Golang paths in bashrc
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Then we save and close .bashrc file. Then we reload and update the .bashrc by using following command:
source .bashrc


Checking Installation

Now we are ready to go. To check if it is everything working perfectly or not we should crate a "hello world" file in go language and run it.
sudo mousepad helloworld.go
Then we add the following code into the file:

package main
import "fmt"
func main() {
fmt.Printf("Hello world!\n")
}

Then we save the file and run it by using following command:
go run helloworld.go
If everything is alright then we got a 'Hello World!' output.

Installing Golang manually

If there is any problem to install it from the repository we can install it from manually.

First we open a browser and go to the official download page of Golang to download it:

Download golang from official website
Download Golang from official website

Then we click in the Linux download as shown in above screenshot to start the download process. The download is almost 120 MB.

The compressed file of Golang will be downloaded to our Downloads folder. We open a terminal window, and to navigate to Downloads folder we use following command:
cd Downloads
Then we type following command to extracts the files:
tar -C /usr/local/ -xzf go*.tar.gz
Above command will extract the Golang in our /usr/local directory.

Configuring Golang

We need to add variables for Golang by modifying the ~/.bashrc file.

First we open the file on our mousepad text editor by using following command:
sudo mousepad ~/.bashrc
Then we paste these following paths at the end of .bashrc file

# Golang paths in bashrc
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Then we save and close .bashrc file. Then we reload and update the .bashrc by using following command:
source ~/.bashrc
Then we can check the installation is correct or not as the process mentioned above (try the same helloworld.go).


In the above described ways we can install Golang manually and from the repository. This now looks so essential because some grate cyber security weapons are available in Golang.

Enjoyed our articles ? Make sure to follow us on Twitter and GitHub, we post article updates there. To join our KaliLinuxInfamily, join our Telegram Group. We are trying to build a community for Linux and Cybersecurity. For anything we always happy to help everyone on the comment section. As we know our comment section is always open to everyone. We read each and every comment and we always reply.
author-img
Kali Linux

Comments

9 comments
Post a Comment
  • sickwizOctober 17, 2020 at 12:27 AM

    export GOROOT=/usr/lib/go
    > It should be usr/local/go

    Delete Comment
    • Kali Linux photo
      Kali LinuxOctober 17, 2020 at 8:16 AM

      Thanks a lot. Kindly check, we have updated it.

      Delete Comment
      • AnonymousDecember 27, 2020 at 8:22 PM

        For me it was "export GOROOT=/usr/lib/go"

        Delete Comment
      • AnonymousDecember 12, 2020 at 9:25 PM

        It was really helpful. Thank you!

        Delete Comment
        • Prince Ezio photo
          Prince EzioApril 26, 2021 at 10:36 PM

          i'm not able to refresh the bashrc file itz showing some errors

          Delete Comment
          • Prince Ezio photo
            Prince EzioApril 26, 2021 at 10:40 PM

            /home/durai/.bashrc:16: command not found: shopt
            /home/durai/.bashrc:24: command not found: shopt
            /home/durai/.bashrc:127: command not found: shopt
            /usr/share/bash-completion/bash_completion:45: command not found: shopt
            /usr/share/bash-completion/bash_completion:53: command not found: complete
            /usr/share/bash-completion/bash_completion:56: command not found: complete
            /usr/share/bash-completion/bash_completion:59: command not found: complete
            /usr/share/bash-completion/bash_completion:62: command not found: complete
            /usr/share/bash-completion/bash_completion:65: command not found: complete
            /usr/share/bash-completion/bash_completion:68: command not found: complete
            /usr/share/bash-completion/bash_completion:71: command not found: complete
            /usr/share/bash-completion/bash_completion:74: command not found: complete
            /usr/share/bash-completion/bash_completion:77: command not found: complete
            /usr/share/bash-completion/bash_completion:80: command not found: complete
            /usr/share/bash-completion/bash_completion:1573: parse error near `|'

            \[\e]0;\u@\h: \w\a\]\[\033[;32m\]┌──(\[\033[1;34m\]\u㉿\h\[\033[;32m\])-[\[\033[0;1m\]\w\[\033[;32m\]]\n\[\033[;32m\]└─\[\033[1;34m\]$\[\033[0m\]

            i get these errors
            if I try to refresh bashrc file

            Delete Comment
            • Kali Linux photo
              Kali LinuxApril 28, 2021 at 5:40 PM

              Which version of Kali Linux you are using?

              Delete Comment
              • Unknown photo
                UnknownJune 29, 2021 at 10:13 PM

                i get similar error he is getting.

                Command 'shopt' not found, did you mean:
                command 'shout' from deb libshout-tools
                Try: sudo apt install
                Command 'shopt' not found, did you mean:
                command 'shout' from deb libshout-tools
                Try: sudo apt install
                Command 'shopt' not found, did you mean:
                command 'shout' from deb libshout-tools
                Try: sudo apt install
                Command 'shopt' not found, did you mean:
                command 'shout' from deb libshout-tools
                Try: sudo apt install
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                /usr/share/bash-completion/bash_completion:1573: parse error near `|'

                \[\e]0;\u@\h: \w\a\]\[\033[;32m\]┌──(\[\033[1;34m\]\u㉿\h\[\033[;32m\])-[\[\033[0;1m\]\w\[\033[;32m\]]\n\[\033[;32m\]└─\[\033[1;34m\]$\[\033[0m\]

                Delete Comment
              • AnonymousJune 30, 2021 at 10:26 PM

                I also get errors

                Command 'shopt' not found, did you mean:
                command 'shout' from deb libshout-tools
                Try: sudo apt install
                Command 'shopt' not found, did you mean:
                command 'shout' from deb libshout-tools
                Try: sudo apt install
                Command 'shopt' not found, did you mean:
                command 'shout' from deb libshout-tools
                Try: sudo apt install
                Command 'shopt' not found, did you mean:
                command 'shout' from deb libshout-tools
                Try: sudo apt install
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                complete: command not found
                /usr/share/bash-completion/bash_completion:1573: parse error near `|'
                exportiere: command not found

                \[\e]0;\u@\h: \w\a\]\[\033[;32m\]┌──(\[\033[1;34m\]\u㉿\h\[\033[;32m\])-[\[\033[0;1m\]\w\[\033[;32m\]]\n\[\033[;32m\]└─\[\033[1;34m\]$\[\033[0m\]

                Delete Comment
                google-playkhamsatmostaqltradent