Skip to content

Kotlin Installation — Complete Setup Guide

DodaTech Updated 2026-06-28 6 min read

Installing Kotlin requires the Java Development Kit and the Kotlin compiler. This guide covers setup on Windows, macOS, and Linux using multiple methods, plus IDE configuration for IntelliJ IDEA and Android Studio.

What You'll Learn

  • Install JDK 21 or later for Kotlin development
  • Install the Kotlin compiler via SDKMAN, Homebrew, or package managers
  • Set up IntelliJ IDEA Community Edition
  • Configure Android Studio for Kotlin
  • Verify your installation with a Hello World program
  • Use the Kotlin REPL for experimentation

Why It Matters

A correct development environment is the foundation for learning Kotlin. Misconfigured JDK versions, missing PATH entries, or wrong IDE settings cause frustration and block progress. By following this guide step by step, you avoid common setup errors and start writing Kotlin code immediately. Whether you target Android, backend, or multiplatform projects, the initial setup is the same.

Real-World Use

DodaTech uses SDKMAN to manage multiple JDK and Kotlin versions across development machines. This approach ensures consistent tooling for every team member. CI/CD pipelines on GitHub Actions install Kotlin via the official setup-action, mirroring local development environments exactly.

Learning Path

flowchart LR
  A[What is Kotlin] --> B[Installation\nYou are here]
  B --> C[Kotlin Basics]
  style B fill:#f90,color:#fff

Prerequisites

Kotlin requires a Java Development Kit. Kotlin 2.0+ requires JDK 21 or later. Earlier Kotlin versions work with JDK 17.

Check if Java is already installed:

java -version
javac -version

If Java is not installed, download JDK 21 from Oracle or use a package manager.

Installing the JDK

macOS

brew install openjdk@21

After installation, link the JDK:

sudo ln -sfn /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk \
  /Library/Java/JavaVirtualMachines/openjdk-21.jdk

Linux (Ubuntu/Debian)

sudo apt update
sudo apt install openjdk-21-jdk

Windows

Download the JDK 21 MSI installer from oracle.com and run it. Add JAVA_HOME to environment variables:

  • Set JAVA_HOME to C:\Program Files\Java\jdk-21
  • Add %JAVA_HOME%\bin to the PATH

Installing the Kotlin Compiler

SDKMAN manages multiple JDK and Kotlin versions.

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 21.0.3-tem
sdk install kotlin

Output: SDKMAN installs the latest Kotlin compiler and sets it as the default.

Using Homebrew (macOS)

brew install kotlin

Using Package Manager (Linux)

# Ubuntu/Debian
sudo snap install kotlin --classic

# Arch Linux
sudo pacman -S kotlin

Manual Installation for Windows

Download the Kotlin compiler ZIP from GitHub releases, extract to C:\kotlin, and add C:\kotlin\bin to the PATH.

Verifying the Installation

kotlin -version

Output: Kotlin version 2.0.21 (JRE 21.0.3+9-LTS)

Now create and run a Hello World program:

// hello.kt
fun main() {
    println("Hello, Kotlin!")
}
kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar

Output: Hello, Kotlin!

The kotlinc command compiles the .kt file into a JAR. The -include-runtime flag bundles the Kotlin runtime so the JAR runs standalone.

Setting Up IntelliJ IDEA

IntelliJ IDEA Community Edition is free and has the best Kotlin support.

  1. Download IntelliJ IDEA Community from jetbrains.com
  2. Run the installer
  3. Open IntelliJ and click New Project
  4. Select Kotlin as the language
  5. Choose JVM as the build system (or Gradle for larger projects)
  6. Click Finish

Creating Your First Project

fun main() {
    val name = "Kotlin Developer"
    println("Welcome, $name!")
    println("Your project is ready.")
}

Output: Welcome, Kotlin Developer! followed by Your project is ready.

IntelliJ detects the Kotlin plugin automatically. The project uses Gradle by default, which downloads dependencies and manages builds.

Setting Up Android Studio

Android Studio includes Kotlin support out of the box.

  1. Download Android Studio from developer.android.com
  2. Run the installer and follow the setup wizard
  3. Open Android Studio and click New Project
  4. Select Empty Compose Activity (uses Kotlin by default)
  5. Configure the project name and package
  6. Click Finish

Android Studio uses Gradle with the Kotlin Android plugin. The build.gradle.kts file configures Kotlin compilation.

Using the Kotlin REPL

The REPL (Read-Eval-Print-Loop) is great for experimenting:

kotlinc-jvm

Then type Kotlin expressions interactively:

>>> val x = 10
>>> val y = 20
>>> println("Sum: ${x + y}")
Sum: 30
>>> listOf(1, 2, 3).map { it * 2 }.filter { it > 3 }
[4, 6]
>>> :quit

Output: The REPL evaluates each expression immediately, showing results inline.

Common Mistakes

  1. Wrong JDK version: Kotlin 2.0 requires JDK 21. Using JDK 17 or earlier causes compilation errors. Run java -version to verify.

  2. Missing PATH entry: After installing Kotlin, the kotlin command may not be found. Ensure the Kotlin bin directory is in your PATH. For SDKMAN users, run sdk env to activate the current version.

  3. Using kotlin instead of kotlinc: The kotlin command runs .kts scripts. The kotlinc command compiles .kt files. Using kotlin to compile produces errors.

  4. Forgetting -include-runtime: Running kotlinc without -include-runtime produces a JAR without the Kotlin standard library. Running it throws ClassNotFoundException.

  5. IDE not detecting Kotlin: In rare cases, IntelliJ needs the Kotlin plugin enabled manually. Go to Settings > Plugins and search for Kotlin.

  6. Gradle wrapper version mismatch: Android Studio projects use a Gradle wrapper. If the wrapper version is too old, Kotlin compilation fails. Update gradle-wrapper.properties to use Gradle 8.5+.

Practice Questions

  1. What is the minimum JDK version required for Kotlin 2.0?

Answer: JDK 21 or later.

  1. How do you check the installed Kotlin version from the command line?

Answer: Run kotlin -version. It prints the version number and the JRE version.

  1. What does the -include-runtime flag do during compilation?

Answer: It bundles the Kotlin standard library runtime into the output JAR, making the JAR self-contained and runnable with java -jar.

  1. How do you run a Kotlin script file (.kts) without compiling?

Answer: Run kotlin script.kts. The kotlin command interprets scripts directly without a separate compilation step.

  1. Challenge: Set up a Kotlin project using only the command line (no IDE). Create a main.kt file, compile it to a JAR, and run it. Then add a dependency on the kotlinx.coroutines library using Gradle.

Answer: Create main.kt, compile with kotlinc main.kt -include-runtime -d app.jar, run with java -jar app.jar. For the Gradle step, create build.gradle.kts with the kotlin plugin and coroutines dependency, then run gradle build && gradle run.

Mini Project

Create a build script that automates Kotlin project setup. Requirements:

  • Prompt the user for a project name
  • Create a directory structure (src/, lib/, build/)
  • Generate a Hello World main.kt file
  • Generate a basic build.gradle.kts with the Kotlin plugin
  • Print instructions for building and running

This project reinforces file I/O, build tools, and the Kotlin/Gradle ecosystem.

FAQ

Do I need Android Studio to learn Kotlin?

No. IntelliJ IDEA Community Edition is sufficient for JVM and multiplatform development. Android Studio is only needed for Android-specific features.

Can I use VS Code for Kotlin?

Yes. Install the Kotlin extension by Microsoft. VS Code offers code completion, debugging, and syntax highlighting, though IntelliJ provides deeper support.

What is the difference between kotlinc and kotlinc-jvm?

kotlinc compiles Kotlin source files to JVM bytecode. kotlinc-jvm is an alias that launches the Kotlin JVM compiler with the REPL.

How do I update Kotlin to the latest version?

With SDKMAN, run 'sdk upgrade kotlin'. With Homebrew, run 'brew upgrade kotlin'. Manual installations require downloading and replacing the compiler.

Why does my IDE show 'Kotlin not configured'?

Open the project structure settings and set the Kotlin SDK path. For Gradle projects, ensure the Kotlin plugin version is specified in build.gradle.kts.

What's Next

After installing Kotlin, dive into Kotlin basics to learn variables, data types, and basic syntax. You can also set up Android development environment if you plan to build mobile apps.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro