How to Install Golang in Linux [New 2023 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 ? 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.

Comments

9 responses to “How to Install Golang in Linux [New 2023 Method]”

  1. sickwiz Avatar
    sickwiz

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

  2. Kali Linux Avatar

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

  3. Anonymous Avatar
    Anonymous

    It was really helpful. Thank you!

  4. Anonymous Avatar
    Anonymous

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

  5. Prince Ezio Avatar

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

  6. Prince Ezio Avatar

    /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: wa][33[;32m]┌──([33[1;34m]u㉿h[33[;32m])-[[33[0;1m]w[33[;32m]]n[33[;32m]└─[33[1;34m]$[33[0m]

    i get these errors
    if I try to refresh bashrc file

  7. Kali Linux Avatar

    Which version of Kali Linux you are using?

  8. Unknown Avatar

    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: wa][33[;32m]┌──([33[1;34m]u㉿h[33[;32m])-[[33[0;1m]w[33[;32m]]n[33[;32m]└─[33[1;34m]$[33[0m]

  9. Anonymous Avatar
    Anonymous

    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: wa][33[;32m]┌──([33[1;34m]u㉿h[33[;32m])-[[33[0;1m]w[33[;32m]]n[33[;32m]└─[33[1;34m]$[33[0m]

Leave a Reply to Kali Linux Cancel reply

Your email address will not be published. Required fields are marked *