Go language or GoLang, in short, is one of the most powerful open source programming languages developed by a small team of Google. It has a huge library function, and it can solve the issues that programmers often face on Python or C/C++. For instance, Python is an easy writing language, but it is a bit slow as it’s an interpreted language. And compiling C/C++ is a bit sluggish. GoLang can solve all the above-mentioned issues and other minor issues. If you’re a programmer and haven’t had any experience with the Go language, I’m sure there is a desire inside you to test the GoLang. Installing GoLang is a piece of cake and is available for Windows, Mac, and Linux.
GoLang on Linux
With a strong and standalone library and better runtime management, GoLang has really been loved by programmers. It can reduce compilation errors and save time. As a Linux user, you might have been thinking about the GoLang dependencies; well, GoLang does have its own system where you can manage the GoLang dependencies. In this post, we will see how to install and get started with GoLang on a Linux system.
We will cover individual methods to install GoLang on Debian, Fedora, and Arch Linux systems in the entire post. Besides that, we will also see all the major methods that you can use to install GoLang on your Linux-based system.
1. Install GoLang on Debian
Installing the GoLang on a Debian-based distribution is easy and straightforward. You just need to get some PPA repository on your machine and update it to install GoLang on your machine. Run the following PPA command given below to your terminal shell to get the PPA.
sudo add-apt-repository ppa:longsleep/golang-backports
Now, update your package repository, then execute the aptitude command given below with root privilege to install GoLang on your Debian Linux system.
sudo apt update sudo apt install golang-go
2. Install GoLang on Fedora Workstation
If you’re a Fedora workstation user, first, run the DNF update command to update the system repository, then run the DNF command to install the Go language directory on your system from the official Linux repository.
sudo dnf -y update sudo dnf -y install go
When the installation finishes, run the given command to check the version of Go Language.
$ go version
3. Install GoLang on Arch Linux
Installing GoLang on an Arch-based system is almost similar to install it on the Fedora system. First, update your system repository by running the following Pacman command given below.
sudo pacman -Syu
Now, run the next Pacman command with root access to install GoLang on your Arch-Linux. I’ve tested this command on Manjaro Linux, and you can also execute this command on other Arch-based systems as well.
sudo pacman -S go
4. Download The GoLang File and Install on Linux
Downloading the source code from the official website of any tool and install it on a Linux system is still the best classic method of installing a program on a Linux system. This method will be executable in all major Linux distributions.
First, you need to download the compressed Linux version of GoLanng on your system. You can find the compressed file on the official Go Language website. Once the download finishes, you will find it in the home directory.
Now, extract the GoLang source file into the /usr/local/go directory on your Linux filesystem. If your system doesn’t have the Go directory inside the /usr/local/ directory, please create one. Now, add a path to the Go directory in your filesystem. This little path exporting will allow you to make the file executable.
export PATH=$PATH:/usr/local/go/bin
When the path exporting finishes, the changes will be applied to your system after the next restart. If you want to see an immediate impact, please run the following command with root access on the terminal shell.
$HOME/.profile.
Finally, run the command given below to check the Go version to know if your installation is successful.
$ go version
5. Use Wget Tool to Download and Install GoLang
The wget tool is the most used tool to download files, applications, source codes on Linux-based systems. First, run the following wget command on your shell to download the GoLang compressed file in your filesystem.
$ sudo wget https://golang.org/dl/go1.15.5.linux-amd64.tar.gz
When the download ends, extract the file by running the tar command given below on the terminal shell with root access.
$ sudo tar -C /usr/local -xzf go1.15.5.linux-amd64.tar.gz.1
Now, add the path on your filesystem to make the GoLang executable on the Linux system.
export PATH=$PATH:/usr/local/go/bin
Finally, run the bashrc command to reload and refresh the GoLang files. Then check the GoLang version to know whether the GoLang is installed correctly or not.
$ source ~/.bashrc $ go version
6. Snap Method to Install GoLang on Linux
As of now, the Snap store and daemon are available for almost every major distribution, and you can use the Snap method to install any popular applications on your system. For example, installing GoLang on a Linux system requires installing the Snap daemon on the system.
If you are using a Debian-based Linux system, use the following commands with root access given below to install Snapd on the system.
sudo apt update sudo apt install snapd
Fedora workstation users can use the following DNF command to get the Snap daemon on the machine. Then run the next command to create a symbolic link for the Snap daemon on your system.
sudo dnf install snapd sudo ln -s /var/lib/snapd/snap /snap
Manjaro and other Arch-based Linux users can use the following Pacman command to install the Snap daemon on the system.
sudo pacman -S snapd
Then run the system control command given below to enable the Snap socket and the ln command to create a symbolic link for Snapd on your system.
sudo systemctl enable --now snapd.socket sudo ln -s /var/lib/snapd/snap /snap
Finally, when the Snapd installing finishes on your system, please run the following Snap command with root access to install the GoLang on your Linux system.
sudo snap install go --classic
7. Use cURL to Download GoLang
In method 2, we already have seen the wget method of installing GoLang on a Linux system. Here, we will see the cURL method of installing GoLang on Linux. You might need to use the cURL instead of wget because sometimes wget might not be able to pull the data on your machine from the server due to location and zone errors, where cURL can pull it easily. So, if you don’t have the cURL tool installed on your machine, please install it first.
Now, browse a directory where you want to save the GoLang file on your system. Then run the cURL command given below on your terminal shell to download the compressed version of GoLang.
cd ~ curl -O https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
When the download ends, run the tar command given below to extract the file. You can also manually unzip the file if you want.
tar xvf go1.10.3.linux-amd64.tar.gz
Now, run the change ownership command on your terminal shell to make the file executable on your system.
sudo chown -R root:root ./go
Then run the move command to move the entire file folder inside the /usr/local directory.
sudo mv go /usr/local
You can now run the following nano command on your shell with root access to edit the configuration script.
sudo nano ~/.profile
When the script opens, add the given lines inside the script the save and exit the script.
export GOPATH=$HOME/work export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
Finally, run the following command to refresh the source files; you can then check the GoLang version to start with the GoLang on your Linux system.
source ~/.profile $ go version
Get Started with GoLang on Linux
Till now, we have seen all the possible methods of installing GoLang on a Linux system. Now it’s time to get started with GoLang. After writing a GoLang code, we need to save the file with a .go
extension. Or, we can first create a file, then we can populate the file with code.
You can run the following cat command to make a file.
$ cat > hello-world.go
Once the file is created, populate the file with the following Go code. This code will return a ‘Hello, UbuntuPIT’ in return.
package main import "fmt" func main() { fmt.Println("Hello UbuntuPIT") }
When you’re done creating the Go code, run the file on your terminal shell with the following Go command. Again, make sure you are browsing the right directory while running the script.
$ go run hello-world.go
Remove GoLang From Linux
Removing GoLang from a Linux machine is easy and straightforward. As we used a source file to load the GoLang, we will need to remove that from our system and remove the user files.
You can the following rm-rf command to remove the Go files from your local directory.
$ sudo rm -rf /usr/local/go
You can also edit and remove the GoLang entry path from the bashrc file.
$ sudo nano ~/.bashrc $ source ~/.bashrc
Final Words
GoLang is a strong and statically typed programming language. The variables don’t get changed with time. In addition, Go is a garbage collected language, which means you don’t need to manage your memory on the system, Go does that by itself.
With a quick overall view and user experience, I am convinced, GoLang is a pretty nifty programming language. In the entire post, I’ve described the methods of installing GoLang on a Linux system.
I hope this post has been informative for you; please share this post with your friends and the Linux community. You can also write down your opinions in the comment section regarding this post. Finally, if you have questions and queries about GoLang, please surf the GoLang community; they have an excellent community.