How to install golang on linux

Installing Go (also known as Golang) on a Debian-based system is easy and can be done in a few steps. Here's how to do it:

  1. Download the Go binary package: Go is available for download from the official Go website (https://golang.org/dl/). Click on the link for the latest stable release, and then download the binary package for Linux.
  2. Extract the package: The Go binary package is a tarball, so you will need to extract the files from the tarball. You can do this using the tar command. For example:
tar -xvf go1.x.x.linux-amd64.tar.gz

This will create a new directory containing the extracted files.

  1. Move the extracted directory: Next, move the extracted directory to the location where you want to install Go. A common location is /usr/local. You can use the mv command to do this. For example:
sudo mv go /usr/local
  1. Set the GOROOT environment variable: Go requires the GOROOT environment variable to be set to the location where Go is installed. You can set this variable by adding the following line to your ~/.bashrc file:
export GOROOT=/usr/local/go
  1. Add Go to your PATH: Finally, you will need to add the bin directory of the Go installation to your PATH environment variable. You can do this by adding the following line to your ~/.bashrc file:
export PATH=$PATH:/usr/local/go/bin

Save the ~/.bashrc file and then run the following command to apply the changes:

source ~/.bashrc

That's it! Go should now be installed and ready to use on your system. You can verify the installation by running the go version command, which should print the version of Go that you have installed.