How to install Kotlin on Ubuntu 22.04

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. In this post, you will learn how to install Kotlin on Ubuntu 22.04. This modern language is intended to replace Java in key processes of Android and other components where it reigned supreme.

According to the Kotlin website:

Kotlin is a modern but already mature programming language aimed to make developers happier. It’s concise, safe, interoperable with Java and other languages, and provides many ways to reuse code between multiple platforms for productive programming.

One of the great advantages of Kotlin is that it aims to simplify many of the things that Java has not been able to. This makes it a bit of lighter, and it is also being considered as a replacement.

Kotlin can be used as a backend language, frontend language, to make libraries and even as a scripting language. So, it is very flexible for many things.

Moreover, it even works with the JVM, so it will run on almost any current operating system.

Install Kotlin on Ubuntu 22.04

Kotlin is included in each IntelliJ IDEA and Android Studio release. So, downloading and installing some of these two IDEs will make the whole process easier, but what if we don’t want to? Well, we can download and install the compiler manually.

First, open a terminal and update the whole computer

sudo apt update
sudo apt upgrade

Then, it is convenient to install the OpenJDK. To achieve this, run.

sudo apt install openjdk-11-jdk

The next step is just to install Kotlin using Snap. This way is one of the easiest and most straightforward.

sudo snap install --classic kotlin

Sample output:

kotlin 1.7.20 from jetbrains✓ installed

So, you will have the compiler in place. Let’s test it.

Testing Kotlin on Ubuntu 22.04

Now, the best way to know if Kotlin is properly installed is to test it. To achieve this, create a kt file.

nano hello.kt

Then, inside it add some simple code like a Hello World.

fun main() {
println("Hello World!")
}

Save the changes and close the editor.

Now compile it

kotlinc hello.kt -include-runtime -d hello.jar

Finally, run it

java -jar hello.jar
Using Kotlin on Ubuntu 22.04
Using Kotlin on Ubuntu 22.04

So, Everything is fine.

Conclusion

In this post, you learned how to install Kotlin on Ubuntu 22.04 in a quick and easy way. So, now it’s up to you to use it and get the most out of it.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook