Install Kotlin & Set Up
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
| Tool | Install needed? | Best for |
|---|---|---|
| Kotlin Playground | No, runs in the browser | Trying examples, sharing small snippets |
| IntelliJ IDEA | Yes | Console apps, servers, learning the language properly |
| Android Studio | Yes | Android apps with Jetpack Compose |
kotlinc command-line compiler | Yes, plus a JDK | Understanding 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:
- Download IntelliJ IDEA from
jetbrains.com/ideaand install it. - Choose New Project, then Kotlin in the list on the left.
- 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). - 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:
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:
./gradlew runOn 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.zipfrom the Kotlin releases page on GitHub (github.com/JetBrains/kotlin/releases), unzip it (for example toC:\kotlinc), and add thebinfolder (C:\kotlinc\bin) to your PATH. - macOS:
brew install kotlinwith Homebrew. - Linux and macOS:
sdk install kotlinwith SDKMAN, orsudo snap install --classic kotlinon Ubuntu.
Open a new terminal and check that the compiler is found:
kotlinc -version
where.exe kotlincThe 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:
fun main() {
println("Namaste from the command line!")
}Compile it into a runnable .jar file, then run it with Java:
kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jarNamaste 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
binfolder is not on your PATH, or you did not open a new terminal after changing it. - No JDK installed.
kotlincand Gradle both need Java. Install a JDK and checkjava -version. - Forgetting
-include-runtime. Without it,java -jar hello.jarfails 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.ktsfile. - 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.jarcompiles a program, andjava -jar app.jarruns it.- Kotlin/JVM needs a JDK; a file
Main.ktbecomes the JVM classMainKt.
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
fun main() {
println("Meera")
println("Lucknow")
}kotlinc me.kt -include-runtime -d me.jar
java -jar me.jarMeera 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?
The Playground runs in the browser at play.kotlinlang.org.
2. What does -include-runtime do in kotlinc hello.kt -include-runtime -d hello.jar?
Without the Kotlin runtime in the jar, java -jar cannot find Kotlin's library classes.
3. In a Gradle project, which file holds the build settings written in Kotlin?
Kotlin projects use the Kotlin DSL file build.gradle.kts.
4. What JVM class name does the compiler create for the top-level code in Main.kt?
Top-level functions in Main.kt are placed in a class named MainKt.
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
