Elemental SystemsSilicon · Boards · Software

Set Up Your Language · 13 of 14

Setting Up Kotlin

Kotlin is a modern language from JetBrains and Google's preferred language for Android apps. It runs on the Java Virtual Machine and works together with Java code, but needs much less typing. Because it runs on Java, you need Java installed first.

Set-up: Medium (needs Java)Official source: kotlinlang.orgFile ending: .kt

New to all this? Read Before you start on the main page first: it shows how to open Terminal, make a folder for your code, and see file name endings. It takes five minutes and prevents most problems.

1 What to download, and from where

Download only from kotlinlang.org, the official Kotlin website by JetBrains; the compiler download is on JetBrains' GitHub page, linked from there. Other download sites can bundle unwanted software.

  1. First install Java by following the Java set-up page, up to and including the version check.
  2. Go to kotlinlang.org/docs/command-line.html and follow its link to the GitHub Releases page (github.com/JetBrains/kotlin/releases).
  3. On the latest release, scroll to Assets and download kotlin-compiler-version.zip.

2 Install it on Windows

  1. Open the zip in your Downloads folder, click Extract all, and extract it to C:\. You should now have a folder C:\kotlinc with a bin folder inside.
  2. Add C:\kotlinc\bin to your PATH (step-by-step instructions), then close and reopen Terminal.

3 Check that it worked

Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. Then type this and press Enter:

kotlinc -version

What you will see: The Kotlin version, and in brackets the Java version it found. It can take several seconds the first time.

info: kotlinc-jvm 2.2.21 (JRE 25.0.1+8-LTS)

If you see an error such as "is not recognized" instead, look at the common mistakes at the bottom of this page.

4 Write and save your first program

A program is just a text file. You can write it in Notepad, which comes with Windows. (Later you may like the free Visual Studio Code editor from code.visualstudio.com, which colours the code and helps spot mistakes.)

  1. Open Notepad (press the Windows key, type Notepad, press Enter).
  2. Type the program below, or click Copy and paste it in with Ctrl + V. Every symbol matters, so copy it exactly.
    fun main() {
        println("Hello, World!")
    }
  3. In Notepad choose File → Save as. Go to your C:\code folder. Set Save as type to All files (*.*), type the file name hello.kt exactly as shown, including the dot and the ending, and click Save.

fun main() is where the program starts ("fun" is short for function). println prints a line.

Do not use Word. Word saves extra formatting and changes straight quotes " into curly ones “ ”, which no programming language accepts.

5 Run it and see the result

Two steps: compile into a .jar file (a packed Java program), then run it with Java.

Open File Explorer, go into your C:\code folder, right-click an empty part of the window and choose Open in Terminal. (More ways to open Terminal.) If Terminal was already open from the check above and is in another folder, type cd C:\code and press Enter.

Type these lines one at a time, pressing Enter after each:

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

What you will see: the words below on a new line. That is your program running.

Hello, World!

-include-runtime packs Kotlin's own library into the jar, and -d hello.jar names the output. Compiling is slow (10 seconds or more); that is normal. For Android apps and bigger projects, JetBrains recommends their free IntelliJ IDEA editor, and Android Studio for Android.

Congratulations: you have written and run a Kotlin program.

6 Common beginner mistakes and how to fix them

Error messages look alarming but are usually precise: read the first line, and look for a line number. If you are stuck, copy the whole error message and paste it into an AI assistant along with your code, and ask what it means.

'java' is not recognized, or ERROR: JAVA_HOME is not set

Why: Kotlin needs Java, and cannot find it.
Fix: follow the Java page, including the Set JAVA_HOME variable option, then reopen Terminal.

Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics

Why: you left out -include-runtime, so the jar is missing Kotlin's library.
Fix: compile again with the exact command above.

'kotlinc' is not recognized as an internal or external command

Why: Windows cannot find the program. Either the Terminal was open before you installed it, or the program's folder is not on the PATH (the list of folders Windows searches for commands).
Fix: Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. If it still fails, restart the computer, then check the folder is on the PATH (how to check and add it). The folder to add is C:\kotlinc\bin.