Installing the Kotlin Compiler

Kotlin is a new statically typed language from JetBrains. JetBrains is known for its popular Java IDE IntelliJ. Kotlin was recently open sourced and the compiler made available through Github. This article will show the steps necessary to build and install the compiler and run a program.

Installation

JetBrains has released the source code of the compiler on Github. Assuming you have Git already installed you can simply clone the project by typing the following command into your command line.

git clone https://github.com/JetBrains/kotlin.git

This will create a copy of the repository on your local hard drive. In order to build the compiler we need to install the Ant build tool. You can either download a binary distribution of Ant or install it with your package manager.

sudo apt-get install ant

To build the project you need to run the following ant command. This will first setup required dependencies and then build the compiler into the dist directory.

  • intellij-core: is a part of command line compiler and contains only necessary APIs.
  • idea-full: is a full blown IntelliJ IDEA Community Edition to be used in former plugin module.
ant -f update_dependencies.xml
ant -f build.xml

This process will take a while. So why not take a look at the web demo of Kotlin and play around with the language?

Hello World

We are now ready to write the first program in Kotlin. As always, we will start by writing a "Hello World" program that simply prints the string "Hello World" to the console.

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

For more information about Kotlin I encourage you to read the documentation and to dive deeper into Kotlins integration with Java have a look at the DZone article about Kotlin + Guice.