This tutorial will help you install Go(Golang) on a Manjaro/Arch Linux system. This guide can also work for other Linux systems like Debian or Ubuntu or Redhat based systems.
Go is a statically typed, compiled programming language designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. It’s has always been said to be an easy language for developers to learn quickly.
Golang is very useful for writing light-weight microservices, infrastructure like networked servers and also tools and systems for developers. It can alsobe used for generating APIs that interact with front-end applications. If you want to build a small functional microservice quickly, then Golang is a great tool to use.
Prerequisites
To follow along this guide, ensure that you have:
- An up to date Arch Linux/Manjaro system
- Connection to the internet
- Knowledge of Linux Terminal
Related Content:
Updating the server
Before proceeding, it is always a good practice to ensure that your server packages are up to date. Use this command to ensure that server packages are updated
|
|
Also make sure that we have some common packages installed:
|
|
Installing Go
Golangis not available in the default Arch Linux/Manjaro repositories. Instead, it is available as a downloadable package from the Golang website downloads page https://go.dev/dl/. We are going to download the Linux package.
The latest version of Golang as of the writting of this tutorial is 1.22.1
. Download it uing this curl command:
|
|
Extract the archive you downloaded to your desired location in the system. I am extracting it to the/usr/local
directory, creating a Go tree in /usr/local/go
.
|
|
In a system where you do not have access to the root system or if you want to install it for your user alone, you can extract it to a path in the home directory.
Setting up Go Environment
Now that Golang is downloaded to a local path, we need to set up the environment. Golang normally uses the two variables, GOROOT and GOPATH to define the root for golang packages and the location of the working directory. We need to add the golang binary directory to the executable directories as well using the PATH variable.
Add this content to the ~/.bashrc
to achieve the above mentioned. If your system using another shell system like zsh or fish shell, addd these to the respective rc file.
Set the GOROOT location where the Go packages are installed in the system
|
|
Next, let’s set the GOPATH, the location of our working directory. I normally prefer having Golang work in ~/go
, so I will set it using this:
|
|
Finally set up the PATH by appending the go binary paths so we access go binary system wide
|
|
To apply the above chages you need to logout and login back to the shell or use the source
command to apply the changes:
|
|
Verifying the installation and creating Hello World App with Go
Now that you have successfully installed and configured go language on your system, let’s confirm that it is working fine by checking its version:
|
|
Now also verify all configured environment variables using following command.
|
|
Let us create a simple Hello world program to test our installation. Create a file main.go in the current directory and add these content to it.
|
|
Then run the program with this command:
|
|
Conclusion
Congratulations! In this guide, you have learned to install Golang on Manjaro/Arch Linux systems.