How To Install Go Language On OpenSUSE Tumbleweed

Install Go programming language

In this short tutorial, we will learn how to install Go languange on OpenSuse Tumbleweed operating system.

Introduction

In recent years, the Go programming language, commonly referred to as Golang, has gained significant traction in the software development community. Developed by Google engineers Robert Griesemer, Rob Pike, and Ken Thompson, Go is designed for efficiency, readability, and simplicity. In this article, we will explore the key features of Go, its advantages, and why it has become a popular choice for building scalable and reliable software applications.

What is Go?

Go is an open-source programming language that combines the speed of a compiled language like C++ with the simplicity of a dynamic language like Python. It was created with a focus on simplicity, readability, and performance, making it an ideal choice for building fast, concurrent, and efficient software applications.

Key Features of Go

  1. Concurrent and Parallel Processing: Go natively supports concurrency with goroutines and channels, making it easy to write efficient and scalable concurrent programs. Goroutines are lightweight threads managed by the Go runtime, allowing developers to easily write concurrent code.
  2. Fast Compilation: Go’s compiler is fast, enabling quick build times and rapid development cycles. This is particularly advantageous for large codebases and continuous integration workflows.
  3. Static Typing and Type Safety: Go is statically typed, which helps catch errors at compile time rather than runtime. It ensures code correctness and reliability, especially in large codebases.
  4. Built-in Testing Support: Go has a built-in testing framework that makes it easy to write and run tests for your code. Testing is a first-class citizen in the Go ecosystem, promoting a culture of writing robust and reliable software.
  5. Efficient Dependency Management: Go’s package management system, known as “go modules,” simplifies dependency management and ensures reproducible builds. It helps in keeping track of dependencies and versioning across projects.

Installing Go Language on OpenSuse Tumbleweed

To install Go on OpenSuse Tumbleweed is a straight forward process, where the steps are as follow :

  • Prerequisites
  • Update System Packages
  • Download Go binary file
  • Install Go language
  • Testing Go language Installation

1. Prerequisites

At this short tutorial we use OpenSuse Tumbleweed operating system, the same as other Linux distribution, in order to install new software we require :

  • Super user or any normal user with SUDO privileges
  • Zypper repolist enabled on OPENSUSE to install packages.

2. Update System Packages

Before installing Go language on OpenSuse Tumbleweed, it’s a good practice to ensure that our system’s package repository is up to date. For this purpose we can do this by running:

$ sudo zypper refresh
$ sudo zypper update

3. Download the Go Binary File

Download the Go package from the official website. For this purpose we will do the following command line :

$ wget https://go.dev/dl/go1.22.1.linux-amd64.tar.gz

Output :

ramansah@bckinfobckinfo:~> wget https://go.dev/dl/go1.22.1.linux-amd64.tar.gz
--2024-03-29 22:44:01-- https://go.dev/dl/go1.22.1.linux-amd64.tar.gz
Resolving go.dev (go.dev)... 216.239.32.21, 216.239.36.21, 216.239.38.21, ...
Connecting to go.dev (go.dev)|216.239.32.21|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://dl.google.com/go/go1.22.1.linux-amd64.tar.gz [following]
--2024-03-29 22:44:01-- https://dl.google.com/go/go1.22.1.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 172.217.194.93, 172.217.194.91, 172.217.194.136, ...
Connecting to dl.google.com (dl.google.com)|172.217.194.93|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 68965341 (66M) [application/x-gzip]
Saving to: ‘go1.22.1.linux-amd64.tar.gz’

go1.22.1.linux-amd64.tar.gz 100%[=========================================>] 65.77M 2.32MB/s in 24s

2024-03-29 22:44:25 (2.74 MB/s) - ‘go1.22.1.linux-amd64.tar.gz’ saved [68965341/68965341]

Then we do the checksum for this new downloaded file :

$ sha256sum go1.22.1.linux-amd64.tar.gz

Output :

ramansah@bckinfobckinfo:~> sha256sum go1.22.1.linux-amd64.tar.gz
aab8e15785c997ae20f9c88422ee35d962c4562212bb0f879d052a35c8307c7f go1.22.1.linux-amd64.tar.gz

4. Installing Go Languange

To install Go language we need to extract the source file then modify its profile. Here is the steps we have taken for this purpose :

  • Extracting Go source file
$ sudo tar -C /usr/local -xzf go1.22.1.linux-amd64.tar.gz
  • Setting Go Paths

After files are extracted, then we will set the Go path. We can do this by editing the .profile file, which contains a list of commands that the system runs every time you log in. Then set Go’s root value, which tells Go where to look for its files.

The configuration file is located on ~/.bashrc file. We will use the vi editor to edit this file.

# Sample .bashrc for SUSE Linux
# Copyright (c) SUSE Software Solutions Germany GmbH

# There are 3 different types of shells in bash: the login shell, normal shell
# and interactive shell. Login shells read ~/.profile and interactive shells
# read ~/.bashrc; in our setup, /etc/profile sources ~/.bashrc - thus all
# settings made here will also take effect in a login shell.
#
# NOTE: It is recommended to make language settings in ~/.profile rather than
# here, since multilingual X sessions would not work properly if LANG is over-
# ridden in every subshell.

test -s ~/.alias && . ~/.alias || true
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
~
~
~
-- INSERT --

Then create a new ~/go directory and exporting it by using several commands line below :

$ mkdir ~/go
$ export GOPATH=$HOME/go

3. Verify the Go installation by querying its version ;

$ go version

Output :

ramansah@bckinfobckinfo:~> go version
go version go1.22.1 linux/amd64

5. Testing Go Installation

At this stage we will create a simple application to show an application using Go language. This script is to show a simple string.

  • Create a simple script as shown below :
ramansah@bckinfobckinfo:~> vi helloworld.go

Go Example
package main

import "fmt"


func main() {
fmt.Println("hello world from OpenSuse Tumbleweed !")
}
  • Then build the script by using command lines :
ramansah@bckinfobckinfo:~> go run helloworld.go
hello world from OpenSuse Tumbleweed !
ramansah@bckinfobckinfo:~> go build helloworld.go
  1.  
  • Execute the Go application :
ramansah@bckinfobckinfo:~> ./helloworld 
hello world from OpenSuse Tumbleweed !

 

This is it, until this stage the Go installation on OpenSuse Tumbleweed operating system is completed done.

Conclusion

The Go programming language offers a blend of performance, concurrency, simplicity, and scalability that attracts developers looking to build robust and high-performance software applications. With its modern approach to concurrency, efficient compilation, and strong standard library, Go has established itself as a preferred choice for projects ranging from web development to system programming. Whether you’re a seasoned developer or just starting, exploring Go could open up new possibilities for your software development endeavors.

(Visited 53 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *