Install Kotlin & Set Up

Kotlin · Lesson 2 of 29 8 min read Updated

Before you write real Kotlin programs, you need a place to run them. The good news is that you have several choices, from a website that needs no installation at all to a full professional editor. In this lesson you will learn all four common setups and when to use each one.

If you only want to try the examples in this course, start with the Kotlin Playground. When you are ready to build projects, install IntelliJ IDEA. If your goal is Android apps, install Android Studio.

Your options at a glance

ToolInstall needed?Best for
Kotlin PlaygroundNo, runs in the browserTrying examples, sharing small snippets
IntelliJ IDEAYesConsole apps, servers, learning the language properly
Android StudioYesAndroid apps with Jetpack Compose
kotlinc command-line compilerYes, plus a JDKUnderstanding how compiling works, scripts

All of them use the same Kotlin language, so everything you learn in one works in the others.

Option 1: the Kotlin Playground

Open https://play.kotlinlang.org in any browser. You will see an editor with a main function already written. Type your code and press the Run button. The output appears under the editor.

The Playground lets you pick the Kotlin version and the target (JVM, JS, Wasm or Compose for the web). Keep the default JVM target for this course. You can also share a link to your code, which is handy when you ask a friend or teacher for help.

Most examples in this course are small, standard-library programs, so they run in the Playground unchanged. The few that need a library (such as coroutines) will tell you so.

Option 2: IntelliJ IDEA

IntelliJ IDEA is the editor made by JetBrains, the creators of Kotlin, and Kotlin support is built in. Since version 2025.3, IntelliJ IDEA is a single download: the core features, including everything you need for Kotlin, are free, and the extra Ultimate features need a subscription.

Kotlin on the JVM needs a JDK (Java Development Kit). If you do not have one, follow Install the JDK & Set Up; IntelliJ IDEA can also download a JDK for you while creating a project.

To create your first project:

  1. Download IntelliJ IDEA from jetbrains.com/idea and install it.
  2. Choose New Project, then Kotlin in the list on the left.
  3. Give it a name such as hello-kotlin, choose Gradle as the build system and pick a JDK (21 or newer is a good choice).
  4. Tick the option to add sample code and click Create.

IntelliJ IDEA creates a project that uses Gradle, the build tool most Kotlin projects use. Your code goes in src/main/kotlin, and a file such as Main.kt holds the main function. Click the green run arrow in the gutter next to fun main() to run it.

The project settings live in build.gradle.kts, which is itself written in Kotlin. A simple console project looks roughly like this:

Kotlin
plugins {
    kotlin("jvm") version "2.4.21"
    application
}

repositories {
    mavenCentral()
}

kotlin {
    jvmToolchain(21)
}

application {
    mainClass = "MainKt"
}

kotlin("jvm") version "2.4.21" chooses the Kotlin version. mavenCentral() is where libraries are downloaded from. jvmToolchain(21) says which Java version to compile for. mainClass = "MainKt" tells Gradle where main is: a file named Main.kt becomes a class called MainKt on the JVM.

With the application plugin you can also run the project from a terminal inside the project folder:

Terminal
./gradlew run

On Windows, use .\gradlew.bat run in PowerShell. The Gradle wrapper (gradlew) downloads the right Gradle version automatically, so you do not need to install Gradle yourself.

Option 3: Android Studio

Android Studio is Google's official editor for Android apps. It is built on IntelliJ IDEA, so it feels the same. Download it from developer.android.com/studio. When you create a new project and pick the Empty Activity template, you get a Kotlin app that uses Jetpack Compose. Kotlin is the default language.

Android Studio also includes an emulator, so you can run apps on a virtual phone. For learning the language itself, though, IntelliJ IDEA or the Playground is simpler: you avoid waiting for an emulator while you practise loops and functions.

Option 4: the command-line compiler

Installing kotlinc is optional, but it shows you exactly what an editor does behind the scenes. You need a JDK first.

  • Windows: download kotlin-compiler-2.4.21.zip from the Kotlin releases page on GitHub (github.com/JetBrains/kotlin/releases), unzip it (for example to C:\kotlinc), and add the bin folder (C:\kotlinc\bin) to your PATH.
  • macOS: brew install kotlin with Homebrew.
  • Linux and macOS: sdk install kotlin with SDKMAN, or sudo snap install --classic kotlin on Ubuntu.

Open a new terminal and check that the compiler is found:

PowerShell
kotlinc -version
where.exe kotlinc

The first command prints the Kotlin version and the Java version it is using. The second shows which folder the command came from (on macOS and Linux, use which kotlinc instead).

Now create a file named hello.kt:

Kotlin
fun main() {
    println("Namaste from the command line!")
}

Compile it into a runnable .jar file, then run it with Java:

Terminal
kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar
Output
Namaste from the command line!

-d hello.jar sets the output file. -include-runtime packs the Kotlin standard library into the jar, so java can run it on its own. Compiling takes a few seconds because the compiler itself starts up on the JVM; that is normal.

Common mistakes

  • "kotlinc is not recognized". The bin folder is not on your PATH, or you did not open a new terminal after changing it.
  • No JDK installed. kotlinc and Gradle both need Java. Install a JDK and check java -version.
  • Forgetting -include-runtime. Without it, java -jar hello.jar fails because the Kotlin standard library is missing.
  • Running the wrong main. In IntelliJ IDEA, use the run arrow next to the function you want, not an old run configuration.

Key points

  • The Kotlin Playground runs Kotlin in your browser with no installation.
  • IntelliJ IDEA has Kotlin built in and creates Gradle projects with a build.gradle.kts file.
  • Android Studio, built on IntelliJ IDEA, is the tool for Android apps; its Empty Activity template uses Compose.
  • kotlinc file.kt -include-runtime -d app.jar compiles a program, and java -jar app.jar runs it.
  • Kotlin/JVM needs a JDK; a file Main.kt becomes the JVM class MainKt.

Exercise

Set up at least one environment. Then write a program that prints two lines: your name, and the name of your city. If you installed kotlinc, compile it to me.jar from the terminal and run it. Write down the exact commands you used.

Show solution
Kotlin
fun main() {
    println("Meera")
    println("Lucknow")
}
Terminal
kotlinc me.kt -include-runtime -d me.jar
java -jar me.jar
Output
Meera
Lucknow

In IntelliJ IDEA or the Playground you only need the Kotlin file: press the run button instead of typing the two commands.

Quick Quiz

1. Which option lets you run Kotlin without installing anything?

2. What does -include-runtime do in kotlinc hello.kt -include-runtime -d hello.jar?

3. In a Gradle project, which file holds the build settings written in Kotlin?

4. What JVM class name does the compiler create for the top-level code in Main.kt?

Learn Kotlin with a mentor

Free lessons get you started. Our Programming & Software Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call