Table of Contents
How to Install GO in Linux
Follow the steps below to download, install, and configure Go, so that you can use it from any location in the terminal.
Download Golang
The first step is to download the official Golang release.
You can either visit the official Go download page or use the wget
command to download the latest version directly.
For this guide, we’ll use version 1.23.0:
wget https://go.dev/dl/go1.23.0.linux-amd64.tar.gz
This command downloads the Go binary for 64-bit Linux systems.
Remove Previous Installations
If you have a previous installation of Go, you’ll need to remove it to avoid conflicts. Run the following command to remove any existing Go installation from the /usr/local/go
directory:
sudo rm -rf /usr/local/go
This ensures a clean slate for the new installation.
Extract the Tar File
Once the download is complete, extract the Go tar file to the /usr/local
directory.
This is the standard location for system-wide installations on Linux:
sudo tar -C /usr/local -xzf go1.23.0.linux-amd64.tar.gz
This command unpacks the Go binary to the /usr/local/go
directory.
Configure System-Wide Access to Golang
To make Go accessible from anywhere in the terminal, you need to add the Go binary directory (/usr/local/go/bin
) to your system’s PATH
environment variable.
How and where do we add it ?
The /etc/profile
file is a system-wide configuration script that runs whenever a login shell starts.
By adding the Go binary directory to the PATH
variable in this file, you ensure that all users can run Go commands without specifying the full path.
A) Open the /etc/profile
file using any text editor with superuser privileges
sudo nano /etc/profile
B) Add the following line at the end of the file:
export PATH=$PATH:/usr/local/go/bin
This line appends the Go binary directory to your system’s PATH
.
Apply the Changes
Changes made to the /etc/profile
file typically take effect the next time you log in. However, you can apply the changes immediately by sourcing the profile file:
source /etc/profile
This command reloads the /etc/profile
configuration and makes the new PATH
available in your current terminal session.
Verify the Installation
To ensure that Go is installed correctly, check the version by running:
go version
If everything is set up correctly, you should see the installed Go version printed in the terminal, confirming that Go is ready for use system-wide.
Conclusion!
You have successfully installed and configured Golang system-wide on your Linux machine.
By modifying the /etc/profile
file, you’ve made Go accessible to all users, ensuring a consistent development environment across the system.
Happy coding with Go!