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
- Download JDK from Eclipse Temurin
- Run the installer
- Set JAVA_HOME environment variable
- Add %JAVA_HOME%\bin to PATH
Verify installation:
java -version
javac -version
macOS
- Using Homebrew:
brew install openjdk@11
- Or download from Eclipse Temurin
- 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
- Download Kotlin compiler from GitHub releases
- Extract to a directory (e.g., /opt/kotlinc or C:\kotlinc)
- Add bin directory to PATH environment variable
- 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)
- Download IntelliJ IDEA (Community Edition is free)
- Install and run the IDE
- Kotlin plugin comes pre-installed
- Create new project → Kotlin → Console Application
Android Studio
Perfect for Android development with Kotlin:
- Download from Android Developer site
- Kotlin support built-in
- Best for mobile app development
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
- Create a file called
hello.kt
:
fun main() {
println("Kotlin installation successful!")
println("Java version: ${System.getProperty("java.version")}")
}
- Compile and run:
# Compile
kotlinc hello.kt -include-runtime -d hello.jar
# Run
java -jar hello.jar
-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
Next Steps
- Verify your installation by running the test program above
- Explore the Kotlin REPL with simple expressions
- Set up your preferred IDE with a new Kotlin project
- Move on to writing your first complete Kotlin program
Quick Quiz
- What is the minimum Java version required for Kotlin?
- Which IDE is developed by the same company that created Kotlin?
- What does the
-include-runtime
flag do when compiling Kotlin?
Show answers
- JDK 8 or higher (JDK 11+ recommended)
- IntelliJ IDEA (both created by JetBrains)
- It includes the Kotlin runtime in the compiled JAR file, making it self-contained