We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Install Go (Golang) on Linux Mint 21/20

Learn how to – How To Install Go (Golang) on Linux Mint 21/20.

Question: How to install Go on Linux Mint 21/20?, How to install Golang on Linux Mint21/20?. In today’s guide, we will see how you can easily install Go/Golang on Linux Mint. Go is a popular open-source programming language designed for concurrency and is widely known for its efficiency, clean design, expressive, and concise design model.

You have three options of installing Go on Linux Mint.

  1. Install Go on Linux Mint from APT repository
  2. Install Go on Linux Mint from Snap
  3. Install Go on Linux Mint using Golang installer

For Ubuntu refer to: How to Install latest Go on Ubuntu

For RHEL 8 / CentOS 8: How to Install Go on RHEL 8

Method 1: Install Go on Linux Mint from APT repository

This is the easiest method of installing Go on Linux Mint. Simply add the PPA repository by running the command below in your terminal.

sudo apt update && sudo apt install build-essential -y
sudo add-apt-repository ppa:longsleep/golang-backports

Press Enter key when prompted to add the repository and import GPG key required for packages verification.

Repository: 'deb https://ppa.launchpadcontent.net/longsleep/golang-backports/ubuntu/ jammy main'
Description:
Golang 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18 and 1.19 PPA for Ubuntu
More info: https://launchpad.net/~longsleep/+archive/ubuntu/golang-backports
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Adding deb entry to /etc/apt/sources.list.d/longsleep-ubuntu-golang-backports-jammy.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/longsleep-ubuntu-golang-backports-jammy.list
Adding key to /etc/apt/trusted.gpg.d/longsleep-ubuntu-golang-backports.gpg with fingerprint 52B59B1571A79DBC054901C0F6BC817356A3D45E
Hit:1 https://mirror.hetzner.com/ubuntu/packages jammy InRelease
Hit:2 https://mirror.hetzner.com/ubuntu/packages jammy-updates InRelease
Hit:3 https://mirror.hetzner.com/ubuntu/packages jammy-backports InRelease
Hit:4 https://mirror.hetzner.com/ubuntu/security jammy-security InRelease
Get:5 https://ppa.launchpadcontent.net/longsleep/golang-backports/ubuntu jammy InRelease [17.5 kB]
Get:6 https://ppa.launchpadcontent.net/longsleep/golang-backports/ubuntu jammy/main amd64 Packages [4,004 B]
Get:7 https://ppa.launchpadcontent.net/longsleep/golang-backports/ubuntu jammy/main Translation-en [1,896 B]
Fetched 23.4 kB in 1s (21.8 kB/s)
Reading package lists... Done

Once the PPA repository has been added, update your package list index and install Go.

sudo apt update
sudo apt install golang-go

You can confirm installed version using the go version option.

$ go version
go version go1.19.5 linux/amd64

Method 2. Install Go on Linux Mint from Snap

To use snap, you need to have installedsnapd which will provides snap command used to install Go on Linux Mint.

sudo apt update
sudo apt install snapd

Then install Go on Linux Mint.

sudo snap install --classic go

You should see a message like below at the end.

2023-01-19T17:24:55Z INFO Waiting for automatic snapd restart...
go 1.19.5 from Michael Hudson-Doyle (mwhudson) installed

Method 3: Install Go on Linux Mint using Golang installer

The last method you can consider is using official Golang installer for Linux systems.

Download it with wget to your local system.

wget https://storage.googleapis.com/golang/getgo/installer_linux

After downloading the file, make it executable:

chmod +x ./installer_linux

And lastly run the installer from your current terminal shell.

$ ./installer_linux 
Welcome to the Go installer!
Downloading Go version go1.19.5 to /home/jkmutai/.go
This may take a bit of time...
Downloaded!
Setting up GOPATH
GOPATH has been set up!

One more thing! Run `source /home/jkmutai/.bash_profile` to persist the
new environment variables to your current session, or open a
new shell prompt.

Source the ~/.bash_profile to start using Go environment variables in your current session.

$ source ~/.bash_profile
$ go version
 go version go1.19.5 linux/amd64

Your Go PATH when using this method is ~/.go

Set Go PATH – For Method 1&2

Run the commands below to set your set $GOPATH

mkdir -p ~/go/{bin,pkg,src}
echo 'export GOPATH="$HOME/go"' >> ~/.bashrc
echo 'export PATH="$PATH:${GOPATH//://bin:}/bin"' >> ~/.bashrc

Testing your Go environment

Let’s create a simple hello Go program to test our installation of Go on Linux Mint20/19.

mkdir -p ~/go/src/test
vim ~/go/src/test/test.go

Add print Hello Gophers message

package main
import "fmt"
func main() {
    fmt.Printf("Hello, Gophersn")
}

Build test.go file

cd ~/go/src/test
go build

Run binary to test

$ ./test
Hello, Gophers

To install the binary into your workspace’s bin directory, use:

$ go install
$ ls ~/go/bin/
test

To remove it use:

go clean -i

Enjoy your Development with Go Linux Mint Desktop system.

Cart

Your Cart is Empty

Back To Shop