How to Install Golang in Linux [New 2020 Method]

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 ? Then follow us via email subscription and social media like Twitter and Medium. We regularly posts articles related cyber security and Kali Linux.

After installing Golang which tool you gonna use first let us know in the comment section or having any issue installing it ? We always replay.

2 comments:

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

    ReplyDelete
    Replies
    1. Thanks a lot. Kindly check, we have updated it.

      Delete

Please do not spam here. It is comment box not a spambox. Promotional links are not allowed.

Powered by Blogger.