Kotlin - Installation & Toolchain

Setting Up Kotlin Development Environment

Learn how to install and configure everything you need to start developing with Kotlin, from the JDK to your preferred IDE.

Prerequisites

Since Kotlin runs on the JVM, you'll need Java installed on your system:

Java Development Kit (JDK)

Minimum requirement: JDK 8 or higher (JDK 11+ recommended)

Windows

  1. Download JDK from Eclipse Temurin
  2. Run the installer
  3. Set JAVA_HOME environment variable
  4. Add %JAVA_HOME%\bin to PATH

Verify installation:

java -version
javac -version

macOS

  1. Using Homebrew: brew install openjdk@11
  2. Or download from Eclipse Temurin
  3. Update shell profile (.zshrc or .bash_profile)
# Add to ~/.zshrc
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH

Linux (Ubuntu/Debian)

# Install OpenJDK
sudo apt update
sudo apt install openjdk-11-jdk

# Verify installation
java -version
javac -version

Set JAVA_HOME in ~/.bashrc:

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

Kotlin Compiler Installation

Method 1: Command Line (SDKMAN - Recommended)

SDKMAN is the easiest way to install and manage Kotlin versions:

# Install SDKMAN
curl -s "https://get.sdkman.io" | bash
source ~/.sdkman/bin/sdkman-init.sh

# Install latest Kotlin
sdk install kotlin

# Verify installation
kotlin -version

Method 2: Manual Installation

  1. Download Kotlin compiler from GitHub releases
  2. Extract to a directory (e.g., /opt/kotlinc or C:\kotlinc)
  3. Add bin directory to PATH environment variable
  4. Verify: kotlinc -version

Method 3: Package Managers

Homebrew (macOS)

brew install kotlin

Snap (Linux)

sudo snap install --classic kotlin

Chocolatey (Windows)

choco install kotlinc

IDE Setup

IntelliJ IDEA (Recommended)

Best choice for Kotlin development - created by the same company (JetBrains)

  1. Download IntelliJ IDEA (Community Edition is free)
  2. Install and run the IDE
  3. Kotlin plugin comes pre-installed
  4. Create new project → Kotlin → Console Application

Android Studio

Perfect for Android development with Kotlin:

Other IDEs & Editors

Visual Studio Code

  • Install Kotlin extension
  • Lightweight and fast
  • Good for learning

Eclipse

  • Install Kotlin plugin
  • Familiar to Java developers
  • Free and open source

Build Tools

Gradle (Recommended)

Most popular build tool for Kotlin projects:

// build.gradle.kts (Kotlin DSL)
plugins {
    kotlin("jvm") version "1.9.20"
    application
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(kotlin("test"))
}

tasks.test {
    useJUnitPlatform()
}

application {
    mainClass.set("MainKt")
}

Maven

Alternative build tool with XML configuration:

<!-- pom.xml -->
<properties>
    <kotlin.version>1.9.20</kotlin.version>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
</dependencies>

Verification & Testing

Command Line Verification

Test your installation with these commands:

# Check Java installation
java -version

# Check Kotlin compiler
kotlinc -version

# Test Kotlin REPL
kotlinc
>>> println("Hello, Kotlin!")
>>> :quit

Create and Run a Test Program

  1. Create a file called hello.kt:
fun main() {
    println("Kotlin installation successful!")
    println("Java version: ${System.getProperty("java.version")}")
}
  1. Compile and run:
# Compile
kotlinc hello.kt -include-runtime -d hello.jar

# Run
java -jar hello.jar
Beginner Note: The -include-runtime flag includes the Kotlin runtime in the JAR file, making it self-contained. The -d flag specifies the output file name.

Online Alternatives

If you want to try Kotlin without installing anything:

Kotlin Playground

Official online IDE with examples and tutorials

Replit

Cloud-based development environment with Kotlin support

JDoodle

Simple online compiler for quick testing

Troubleshooting

Common Issues

Command not found: kotlinc

  • Check PATH environment variable
  • Restart terminal/command prompt
  • Verify installation directory

Java version compatibility

  • Kotlin requires JDK 8 or higher
  • Use java -version to check
  • Update JAVA_HOME if necessary

IDE doesn't recognize Kotlin files

  • Install Kotlin plugin
  • Restart IDE
  • Check project structure
Teacher Note: For classroom environments, consider using the online Kotlin Playground initially to avoid installation issues. Students can focus on learning the language while you handle local setup gradually.
Architect Note: For production environments, standardize on specific JDK and Kotlin versions. Use build tools like Gradle with version catalogs to ensure consistent dependencies across teams.

Next Steps

  1. Verify your installation by running the test program above
  2. Explore the Kotlin REPL with simple expressions
  3. Set up your preferred IDE with a new Kotlin project
  4. Move on to writing your first complete Kotlin program

Quick Quiz

  1. What is the minimum Java version required for Kotlin?
  2. Which IDE is developed by the same company that created Kotlin?
  3. What does the -include-runtime flag do when compiling Kotlin?
Show answers
  1. JDK 8 or higher (JDK 11+ recommended)
  2. IntelliJ IDEA (both created by JetBrains)
  3. It includes the Kotlin runtime in the compiled JAR file, making it self-contained