Check if you already have installed Go on your machine:
- Check:
Output can be:which go
/usr/local/go/bin/go # OR /usr/bin/go
- Remove the Golang binary:
sudo rm -rvf [path_to_go_binary] sudo rm -rvf /usr/local/go/
- 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:
- To install Go visit the following address: https://golang.org/dl/
- Download archive for Linux platform:
- 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 filetar
command is going to work with - Open
.zshrc
file:vim ~/.zshrc
- Go down to the end of the file and add the following entries for Go variables and Go path:
Here we're specifying Go workspace at:# Go variables and path export GOPATH=/root/go-workspace export GOROOT=/usr/local/go PATH=$PATH:$GOROOT/bin/:$GOPATH/bin
/root/go-workspace
- Save and close the file
- Refresh zsh configuration with:
source ~/.zshrc
- Now check installed version of Go:
go version
Reference
- Uninstalling Go
- How to uninstall Golang in 3 easy steps via terminal
- How to uninstall Go?
- How do I use the tar command?
- Order of execution and purpose of .profile vs .zshrc
- Tar command options and syntax explained
- What does the -f parameter do in the tar command
- How to Extract Tar Files to Specific or Different Directory in Linux