How To Install Go on Manjaro
In this tutorial, we will show you how to install Go on Manjaro. Welcome to our comprehensive guide on installing the Go programming language (often referred to as Golang) on your Manjaro Linux system using the Command Line Interface (CLI). Whether you’re a seasoned developer or just starting your journey with Go, this step-by-step guide will assist you in setting up a productive development environment.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the Go programming language on a Manjaro Linux.
Prerequisites
- A server or desktop running one of the following operating systems: Manjaro, and other Arch-based distributions.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Go.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Go on Manjaro
Step 1. Before running the tutorial below, make sure that our system is up to date:
sudo pacman -Syu sudo pacman -S base-devel
Step 2. Installing Go on Manjaro.
Manjaro provides a straightforward way to install Go. Use ‘pacman
‘ to install the Go programming language:
sudo pacman -S go
After installation, confirm that Go has been installed successfully by running the following command:
go version
If the installation was successful, you will see an output indicating the Go version installed on your system.
Step 3. Setting Up Go Environment Variables.
The GOPATH is your workspace directory for Go projects. Create a directory for your Go workspace (if not already done) and configure GOPATH in your shell profile configuration file, typically ~/.bashrc
or ~/.zshrc
:
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
To easily access Go executables, you should add the Go binary directory to your PATH. Modify your shell profile configuration file (e.g., ~/.bashrc
or ~/.zshrc
) as follows:
echo 'export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin' >> ~/.bashrc
Remember to source your shell profile to apply the changes:
source ~/.bashrc
Step 4. Writing Your First Go Program.
Now that you have Go and a text editor set up, let’s create your first Go program:
mkdir -p ~/go/src/myfirstproject
Replace myfirstproject
with a suitable name for your project.
Let’s create a basic “Hello, World!” program in Go. Use your text editor to create a new file named hello.go
inside your project directory (~/go/src/myfirstproject
):
package main import "fmt" func main() { fmt.Println("Hello, World!") }
Open your terminal and navigate to your project directory:
cd ~/go/src/myfirstproject
Now, you can compile and run your Go program:
go run hello.go
Step 5. Troubleshooting.
During the installation and setup process, you may encounter some common issues. Here are solutions to a few potential problems:
-
Permission Denied: If you encounter permission errors during installation or project creation, use
sudo
or adjust file permissions accordingly. -
Go Version Mismatch: Ensure that the installed Go version matches your system’s architecture (32-bit or 64-bit).
-
GOPATH Errors: If you experience GOPATH-related issues, double-check your environment variable settings and make sure they match your workspace structure.
-
Package Installation Failures: If external package installation fails, ensure your internet connection is stable, and the package path is correct.
Congratulations! You have successfully installed Go. Thanks for using this tutorial to install the latest version of the Go programming language on the Manjaro system. For additional help or useful information, we recommend you check the official Go website.