Download The Ultimate Tutorial: Getting Started With Kotlin

80 pages of hands-on tutorial right into your email inbox. Learn how to use state of the art development environment and build a full-fledged command-line application. You will receive free updates to the tutorial. Start learning Kotlin today!

Starting With Kotlin on Linux

This guide is an add-on to the Ultimate Tutorial: Getting Started With Kotlin (get it here). It explains how to install all the dependencies Kotlin requires.

Looking for Mac OS X? Here is the link to the guide.

Looking for Windows? Here is the link to the guide.

Terminal Emulator

This tutorial assumes you can use a terminal emulator to execute commands to install the dependencies. Skip this section if you already have terminal emulator installed and comfortable using it.

Any Linux distribution will have some terminal emulator available. They all should work for our purposes. Use the one that you feel comfortable with and skip to the next section.

If you never had to launch a terminal emulator on a Linux system before, continue reading this section, as I explain how you can open one in your Linux system.

If you have Ubuntu, you can search for terminal using Ubuntu Dash:


And press Enter when you see it has found the terminal emulator application.


If you have almost any Linux, under GNOME, you can access terminal emulator using the menu of your desktop
Applications > System Tools > Terminal.

If you have almost any Linux, under KDE, you can access terminal emulator using the menu of your desktop
K > System > Terminal (Konsole)​.

If you have almost any Linux, under Xfce, you can access terminal emulator using the menu of your desktop
Applications > System > Xfce Terminal.

Do you have other Linux, and no instructions apply to you? Send me an email to oleksii [@] iwillteachyoukotlin.com with detailed information about your Linux – we will figure something out.

Once you have launched the terminal emulator verify that it works by typing the following command and pressing Enter:

$ echo "Hello, World."

$ is not part of the command – it is just a prompt that terminal application usually outputs. No need to type it. Same applies for any terminal command I ask you to run in this tutorial. If that worked, you should see Hello, World. output like that:

$ echo "Hello, World."
Hello, World.

OpenJDK​​​​

This tutorial assumes you have OpenJDK installed. Skip this section if you already have OpenJDK installed. Though, you might want to update the version of your OpenJDK if it is too old. Then continue reading.

To check if OpenJDK is installed and has proper version run the following command and it should produce the following output:

$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Your openjdk version and other numbers may vary.

If you do not have OpenJDK installed, you will get an appropriate message in the terminal. To install it run the following command in the terminal:

For Debian-Based Systems (Ubuntu, Debian, etc.)

$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk

For RHEL-Based Systems (Fedora, CentOS, Oracle Linux, Red Hat Enterprise Linux, etc.)

$ su -c "yum install java-1.8.0-openjdk"

This command will ask you for your password. Don’t worry – it will not appear on the screen when you will be typing. Finally, when the command execution is complete, you should run java -version and check that its output is similar to what we had a few paragraphs before.

You might need to update you OpenJDK version if it is too old. For that, you should execute the following command:

For Debian-Based Systems (Ubuntu, Debian, etc.) the same as for installation above:

$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk

For RHEL-Based Systems (Fedora, CentOS, Oracle Linux, Red Hat Enterprise Linux, etc.) different from the installation:

$ su -c "yum update java-1.8.0-openjdk"

IntelliJ IDEA

Both Kotlin programming language and IntelliJ IDEA are developed by the same company – JetBrains. As you might guess, IntelliJ has some serious support for that language. The development environment and the programming language are both optimised to work well with each other.

Of course, you can use a plain-text editor and command-line Kotlin compiler. I highly recommend you use proper tools for the job. Don’t worry IntelliJ IDEA Community Edition is free to use and open-source. So you should have no trouble downloading, installing and using it indefinitely for anything you want, including commercial applications.

This tutorial assumes you are using IntelliJ IDEA Community Edition. If you have it installed and configured, you should skip this section. Otherwise, here we go:​​​​

First, download the community edition from the official JetBrains website.

​Then unpack the downloaded .tar.gz file from the terminal emulator. Assuming you have downloaded the file in your ~/Downloads directory:

$ cd ~/Downloads
$ tar -xf ideaIC-2017.2.5.tar.gz

(version may differ for you depending on when you are going through this guide)

Now you can move the directory idea-IC-172.4343.14 (version will be different for you) to where you like to have your IntelliJ installed. I usually create a single directory ~/idea/ where I store all the different versions of IntelliJ that I have downloaded.

You can do it this way:

$ mkdir -p ~/idea/
$ mv idea-IC-172.4343.14 ~/idea/

Now switch to that directory and run IntelliJ starter script:

$ cd ~/idea/idea-IC-172.4343.14/
$ ./bin/idea.sh

At this point, IntelliJ will ask you if you want to import existing IntelliJ settings. As you do not have them, leave Do not import settings choice left and click on the OK button:


Next, Intellij will ask you to accept JetBrains’ Privacy Policy. Read it and click on the button Accept. IntelliJ will ask you what theme you want to use. This tutorial will use the Default, IntelliJ light theme.

At the next step, IntelliJ will ask you if you want to create a desktop entry. That is useful as it will allow you to run IntelliJ as a normal application from Desktop menu (for GNOME and KDE) or Ubuntu Dash. That is more convenient than using the launcher script from the terminal every time.


Make sure Create desktop entry is selected and proceed to the next setup screen by pressing Next button. Next step is about launcher script, we will not need that in the tutorial, and you can create it later if you ever need it. Just click Next button.

IntelliJ will ask you what default plugins you want to use. Leave everything as is and proceed to the next step. Finally, IntelliJ will ask you one last thing: what featured plugins you want to use. Leave everything as is and proceed to the next step.

At this point, you should see IntelliJ loading. As it is loaded, you should see the front screen, which allows you to create a project, import or open the existing one:

Creating a “Hello World” Application

That should be it for dependencies. I highly recommend creating a simple project in Kotlin to see that everything works as expected. Let’s do that right now:

Click on the Create New Project button on the IntelliJ front screen:

After clicking on the button, you should see the Create New Project screen:

At this point choose Kotlin project group in the sidebar:

don’t choose Kotlin/JVM in the main area, as this will create a Java project with Kotlin support.

Now choose Kotlin/JVM in the main view and press Next button:

You should see the screen with all the different options to create your new project:

​As you can see the Project Location is ~/IdeaProjects/untitled. Particularly the part ~/IdeaProjects. That is supposed to be a home directory for all the projects created in IntelliJ IDEA. I discourage you from using that. In our industry, most of the developers, whom I have met, prefer to use ~/workspace as the home directory for any of their projects, no matter if they are IntelliJ-based or not.

​So change IdeaProjects to workspace and change your Project name from untitled to HelloKotlin. Also, make sure the Project Location says ~/workspace/HelloKotlin too. You do not need to change anything else on this screen at this point.

You should see now:

​As we are done filling the details of our new project, let’s click on that Finish button. IntelliJ will ask you if it should create a new directory for your project. Click on the OK button.

Now you should see the workspace of your project:

As this is your first run of Kotlin project in IntelliJ, it will take a minute or so to index all the Kotlin and Java standard libraries.

As soon as it has completed indexing, you should see the sidebar with your project structure:

Now we should create our small hello world application. It will consist of a single file with the main function. The main function is the entry point to any application in Kotlin. When you run the application main function gets executed.

To create a new file, expand HelloKotlin module in the project sidebar. If you do not see the sidebar like on the picture, press Alt + 1. Then select src directory inside of it. src directory is where the code resides in the default project structure created by IntelliJ. Here is what you should see at that point:

​Now to create a new file press Alt + Insert while src directory is selected; alternatively, you could right-click on src directory to bring up the context menu, and the first submenu is New.

Anyways, you should see now this context menu (or submenu):

That menu allows you to type to filter the items. Start typing kotlin to try it out:

​Now press Enter to start the creation of new Kotlin File/Class. Alternatively, instead of using the filter, you could have just clicked with your mouse on Kotlin File/Class or use arrows to select that option.

After initiating the creation of new kotlin file or class, you will see an appropriate dialog, which allows you to choose the kind of kotlin file you want to create and its name:

Now type the name of the kotlin file: Application. Leave kind as it is - File. Finally, press Enter or click on the OK button:

After creating the file, it should automatically open in the main workspace area in the IntelliJ:

Now, the easiest way to create the main function is to type main and press TAB:

After you press TAB, the main function will be auto-generated by IntelliJ. This feature of IntelliJ is called live templates. It allows to type much less, comes with helpful built-in templates, and allows to configure your templates. That is what you should see when the main function is generated:

Now, to print “Hello, Kotlin!” on the screen add the following to your main function:

To run the application press CTRL + SHIFT + F10 while code editor with Application.kt open is active. The application should compile and run. Shortly, you should see the desired output “Hello, Kotlin!”:

Now you should be set to use Koltin with IntelliJ on Linux.

Check out my free Ultimate Tutorial: Getting Started With Kotlin where you will build a real command-line application while learning all the features of Kotlin you will need to construct 80% of any application.

Copyright ©iwillteachyoukotlin.com 2017 - Oleksii Fedorov