How to install the stable version of Go on Kali Linux

How to install the stable version of Go on Kali Linux

Check if you already have installed Go on your machine:

  1. Check:
    which go
    
    Output can be:
    /usr/local/go/bin/go
    # OR
    /usr/bin/go
    
  2. Remove the Golang binary:
    sudo rm -rvf [path_to_go_binary]
    sudo rm -rvf /usr/local/go/
    
  3. Remove the Go bin directory from your PATH environment variable. Remove any reference on $GOPATH or $PATH export definitions in your .zprofile and .zshrc:
    vim ~/.zprofile
    vim ~/.zshrc
    

Install Go on Kali Linux:

  1. To install Go visit the following address: https://golang.org/dl/
  2. Download archive for Linux platform:
    download
  3. Untar archive to the /usr/local/ path:
    tar -C /usr/local/ -xzf go1.17.7.linux-amd64.tar.gz
    
    -C - option is used to specify a different directory other than the current working directory
    -x - is one of the mandatory options (-c, -t, -x) which specifies the command to extract the file from an archive
    -z - optional flag, which specifies to filter the archive file through gzip. This flag is used to extract files from compressed archives. In our case, we are downloading the.tar.gz archive
    -f - option specifies the file tar command is going to work with
  4. Open .zshrc file:
    vim ~/.zshrc
    
  5. Go down to the end of the file and add the following entries for Go variables and Go path:
    # Go variables and path
    export GOPATH=/root/go-workspace
    export GOROOT=/usr/local/go
    PATH=$PATH:$GOROOT/bin/:$GOPATH/bin
    
    Here we're specifying Go workspace at: /root/go-workspace
  6. Save and close the file
  7. Refresh zsh configuration with:
    source ~/.zshrc
    
  8. Now check installed version of Go:
    go version
    

Reference

  1. Uninstalling Go
  2. How to uninstall Golang in 3 easy steps via terminal
  3. How to uninstall Go?
  4. How do I use the tar command?
  5. Order of execution and purpose of .profile vs .zshrc
  6. Tar command options and syntax explained
  7. What does the -f parameter do in the tar command
  8. How to Extract Tar Files to Specific or Different Directory in Linux