1. Download the tar archive
$# Set the Go version to download
$export GO_VERSION=X.Y.Z # Replace X.Y.Z with the version number
$# Set the processor architecture (amd64, arm64 or 386)
$export ARCH=amd64
$# Download the tar archive
$wget https://go.dev/dl/go${GO_VERSION}.linux-${ARCH}.tar.gz
Or go to the Go Downloads page and download the Linux tar archive .tar.gz
.
2. Extract the archive
$# First remove any previous installation if it exists
$sudo rm -rf /usr/local/go
$# Then extract the archive
$sudo tar -C /usr/local -xzf go${GO_VERSION}.linux-${ARCH}.tar.gz
$# You can check installation directory
$ls /usr/local/go
3. Make the Go binaries available globally
To make the Go binaries available globally on your system, you need to add their directories to your PATH
environment variable.
Their are 2 directories that you might want to add to your PATH
:
/usr/local/go/bin
: Go installation binaries~/go/bin
: Binaries of third party tools that you install viago install
Use any of your ~/.profile
, ~/.bash_profil e
or ~/.bashrc
files to add these directories to the PATH
variable:
# Go installation binaries
export PATH="${PATH}:/usr/local/go/bin"
# Third party tools installed via `go install`
export PATH="${PATH}:${HOME}/go/bin"
You can also add both directories on the same line:
export PATH="${PATH}:/usr/local/go/bin:${HOME}/go/bin"
This change will be applied when you open a new terminal window or on you next login.
To apply this change immediately, execute the file that you have changed, for example:
$source ~/.profile
4. Verify the installation
You should be able to run go
from any location:
$go version
go version goX.Y.Z linux/amd64
Update the Go Version
If you want to update the Go version, follow the same installation steps:
$# Set the Go version to download
$export GO_VERSION=X.Y.Z # Replace X.Y.Z with the version number
$# Set the processor architecture (amd64, arm64 or 386)
$export ARCH=amd64
$# Remove the previous Go installation directory
$sudo rm -rf /usr/local/go
$# Download the new tar archive
$wget https://go.dev/dl/go${GO_VERSION}.linux-${ARCH}.tar.gz
$# Then extract the archive to /usr/local
$sudo tar -C /usr/local -xzf go${GO_VERSION}.linux-${ARCH}.tar.gz
$# Verify the installation
$go version
Uninstall Go
To uninstall Go we need to undo what we did previously:
$# Remove the Go directory
$sudo rm -rf /usr/local/go
$# Remove the thrid party tools installed via `go install` if any
$sudo rm -rf ~/go
If you have installed any third party tools using go install
and you want to remove their source files and compiled binaries:
$# Remove the installed thrid party tools
$sudo rm -rf ~/go
Then remove the Go bin directories from your PATH
environment variable.