Home Linux How To Install Go (Golang) 1.18 on KDE Neon / Kubuntu

How To Install Go (Golang) 1.18 on KDE Neon / Kubuntu

0

GO is an open-source programming language designed by Google and launched in 2009. It aims at being a simple, reliable, and efficient programming language. GO is also concurrent in nature, in that you can run multiple tasks using it at the same time on a massive scale.

Golang and GO are the same thing and should not get confused. Golang came from the official website of GO which is golang.org and it is more google-able than GO. GO has a similar syntax to that of the C programming language and if you have a good command over C, then Go will not be a problem for you to master.

Sites like Facebook, Paypal, and Netflix use GO because of its reduced latency, clean and efficient code that easily scales. This is because it easy to install services using Go. Due to its enhanced performance, Go creates fast and scalable web applications.

Features of Go Programming Language

Some of its features include.

  • Used for a variety of software developments like Web and Cloud services
  • Easy to get started and simple to master
  • Fast and thus used with high-end applications
  • Concurrency, the ability to run multiple tasks simultaneously
  • Active Development community and Good Documentation
  • Garbage collection which reduces latency
  • It provides a powerful standard library

The latest release is Go 1.18  which has new features:

  • Introduced new support for generic code using parameterized types which has been a requested feature by most GO users.
  • Fully Intergrated fuzzing, where a random data is run against your test to find for vulnerabilities like denial of service.
  • Introduced Go workspace mode that makes it easy to work on multiple modules.
  • Improved CPU performace
  • Bug-fixes where it can report errors correctly.
  • The compiler can now run inline functions that contain range of loops.
  • Linker that emeits fewer relocationsa making codebases link fastser and require less memory.
  • Garbage collection that include non-heap sources of garbage collector work. This will make some applications use less memory in garbage collection.

In this guide, I will show you how to:

  • Install Go on KDE Neon|Kubuntu using Go Installer.
  • Install Go on KDE Neon|Kubuntu manually.
  • Set PATH environment variable.
  • Write and Compile a sample program.

Install Go (Golang) 1.18 on KDE Neon / Kubuntu

Use one of the methods shared in this section to install Go (Golang) 1.18 on KDE Neon / Kubuntu.

Method 1: Install via Golang Installer on KDE Neon|Kubuntu

Go to go.dev Downloads page to download the latest Go 1.18 Tarball file for Linux and save the file.

Open your Konsole. The first thing to do is to update your package index

sudo apt update

Then change your directory to cd Downloads where the file is saved.

Extract the file using

sudo tar -C /usr/local -xzf go1.18.linux-amd64.tar.gz

It will extract to the /usr/local directory. If you wish to install it somewhere else, you can edit the directory.

Set environment Variable

Add to usr/local/go/bin to the Path Environment variable by typing

export PATH=$PATH:/usr/local/go/bin

The changes might not be applied immediately until the next time you log in to your computer. To apply the changes use,

source ~/.profile

To display your path environment variable use

echo $PATH

The output is as follows.

Then check the version using 

$ go version

It displays the output as follows

Method 2: Install GO Manually on KDE Neon / Kubuntu

Update your package index.

sudo apt update && sudo apt upgrade -y

Add Golang backports PPA repository on your system using the following command.

sudo add-apt-repository ppa:longsleep/golang-backports 

The output is as follows.

 Golang 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 and 1.18 PPA for Ubuntu
 More info: https://launchpad.net/~longsleep/+archive/ubuntu/golang-backports
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Get:1 file:/var/lib/preinstalled-pool focal InRelease
Ign:1 file:/var/lib/preinstalled-pool focal InRelease                                    
Get:2 file:/var/lib/preinstalled-pool focal Release [3,949 B]                            
Get:2 file:/var/lib/preinstalled-pool focal Release [3,949 B]                                    
Hit:3 http://archive.ubuntu.com/ubuntu focal InRelease                                           
Get:4 http://ppa.launchpad.net/longsleep/golang-backports/ubuntu focal InRelease [17.5 kB]       
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease                                 
Get:6 http://archive.neon.kde.org/user focal InRelease [162 kB]                                  
Hit:7 http://archive.ubuntu.com/ubuntu focal-updates InRelease                            
Get:9 http://ppa.launchpad.net/longsleep/golang-backports/ubuntu focal/main amd64 Packages [3,668 B]
Fetched 184 kB in 1s (244 kB/s)    
Reading package lists... Done

Then run the following command to install Golang from the repository.

sudo apt install golang-go

When prompted for disk space, type y to continue the installation. The sample output is shown below.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Starting pkgProblemResolver with broken count: 0
Starting 2 pkgProblemResolver with broken count: 0
Done
The following additional packages will be installed:
  g++ g++-9 gcc gcc-9 golang-1.18-go golang-1.18-src golang-src libasan5 libatomic1 libc-dev-bin
  libc6-dev libcrypt-dev libdpkg-perl libfile-fcntllock-perl libgcc-9-dev libitm1 liblsan0
  libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev manpages-dev pkg-config
Suggested packages:
  g++-multilib g++-9-multilib gcc-9-doc gcc-multilib make autoconf automake libtool flex bison
  gcc-doc gcc-9-multilib gcc-9-locales bzr | brz mercurial subversion glibc-doc debian-keyring
  bzr libstdc++-9-doc dpkg-dev
The following NEW packages will be installed:
  g++ g++-9 gcc gcc-9 golang-1.18-go golang-1.18-src golang-go golang-src libasan5 libatomic1
  libc-dev-bin libc6-dev libcrypt-dev libdpkg-perl libfile-fcntllock-perl libgcc-9-dev libitm1
  liblsan0 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev manpages-dev
  pkg-config
0 upgraded, 25 newly installed, 0 to remove and 0 not upgraded.
Need to get 110 MB of archives.
After this operation, 592 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

Then run the following command to display the version

$ go version

It will show the following output.

go version go1.18 linux/amd64

Create an application

Create a directory to store your file then navigate to that directory.

mkdir Go_Projects
cd Go_Projects

Create a new .go file using your favorite editor in that directory. I will use Nano.

nano hello.go

You can use vim also

Append this code in the file. You can change the message you would want to print.

package main

import "fmt"

func main() {
    fmt.Println("Hello from Technixleo!")
}

Save your file and exit the editor.

To view the contents of the file use,

cat hello.go

It will list the output as follows

To enable dependency tracking of your code, use

go mod init example/hello

This enables your code to use packages that are contained in other modules when you import them. This is done by using a go.mod file that is created using the go init command as shown below.

Next will be to build your code 

go build hello.go

Run your code 

go run .

The output is as follows.

Conclusion

From this guide, you have learned how to install GO on KDE Neon|Kubuntu and set the $GOPATH environment variable. You have also learned how to create and run a sample program.

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version