How to install kotlin programming language on Ubuntu/Debian Linux

Posted on in Categories , , , last updated May 19, 2017

How do I install the latest version of kotlin programming language on Ubuntu or Debian Linux system?

Kotlin is a free and open source statically-typed programming language. It runs on the JVM, and one can compile to JavaScript source code. Kotlin is similar to Apple’s Swift. One can write server-side or Android apps in it. This page shows you how to install the latest version of Kotlin programming language on on Ubuntu or Debian Linux.

Install kotlin using the Software Development Kit (SDK) manager

Type the following command to install sdk:
$ wget -O sdk.install.sh "https://get.sdkman.io"
$ vi sdk.install.sh
$ bash sdk.install.sh

Sample outputs:

Fig.01: Installing SDKMAN
Fig.01: Installing SDKMAN

Type the following commands to install kotlin:
$ source ~/.sdkman/bin/sdkman-init.sh
$ sdk install kotlin

Sample outputs:
Fig.02: Installing kotline
Fig.02: Installing kotline

Install JDK

Type the following command :
$ sudo apt-get install openjdk-8-jre-headless
Sample outputs:

[sudo] password for vivek: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.10.0-19 linux-headers-4.10.0-19-generic linux-image-4.10.0-19-generic linux-image-extra-4.10.0-19-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  ca-certificates-java java-common
Suggested packages:
  default-jre fonts-dejavu-extra fonts-ipafont-gothic fonts-ipafont-mincho ttf-wqy-microhei | ttf-wqy-zenhei fonts-indic
The following NEW packages will be installed:
  ca-certificates-java java-common openjdk-8-jre-headless
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 27.7 MB of archives.
After this operation, 102 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu zesty/main amd64 ca-certificates-java all 20161107 [12.6 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu zesty/main amd64 

Write your first kotlin program

Create a file called hello.kt:
$ vi hello.kt
Append the following code:

fun main(args: Array<String>) {
    println("Hello, World!")
}

Save and close the file. Compile your app into jar:
$ kotlinc hello.kt -include-runtime -d hello.jar
Run your app:
$ java -jar hello.jar
Sample outputs:

Fig.03: Running your first app
Fig.03: Running your first app

For more info see kotlinlang.org.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

1 comment

Leave a Comment