Kotlin is a general-purpose programming language which interoperates fully with Java. Kotlin’s JVM version of its standard library depends on the Java Class Library, hence this tutorial will first show the reader how to install Java SDK and then a Kotlin compiler on Ubuntu 20.04.
In this tutorial you will learn:
- How to install Java SDK
- How to install Kotlin compiler
- How to compile simple Kotlin program
- How to run Kotlin program
Software Requirements and Conventions Used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa |
Software | Kotlin Compiler, OpenJDK java |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
How to install Kotlin on Ubuntu 20.04 step by step instructions
- Install desired Java version. For example in this case we will go with Java
openjdk-11-jdk
:$ sudo apt install openjdk-11-jdk
- Next step is to install Kotlin:
$ sudo snap install --classic kotlin
- Use any text editor and create a file called
hello.kt
with the following content:fun main() { println("Hello World!") }
- Compile the Kotlin source code:
$ kotlinc hello.kt -include-runtime -d hello.jar
-
Run the actual Kotlin program:
$ java -jar hello.jar Hello World!