← Back to Kotlin Course | Chapter 1: Setup & Basics | Lesson 2 of 7

Installing Kotlin

Installing Kotlin means putting the Kotlin compiler on your computer so it understands and can run Kotlin code.

Installing the JDK First

Kotlin compiles to JVM bytecode, so a Java Development Kit must be installed before the Kotlin compiler will work. Most systems use JDK 11 or newer; running java -version confirms one is already present.

Note: If java -version fails, install a JDK (e.g. Temurin or OpenJDK) before installing Kotlin.

Example: Installing the JDK First

bash
# Linux/macOS (SDKMAN)
sdk install java 21-tem

# Windows
# Download JDK from https://adoptium.net and run the installer

⚠️ Run this command in your terminal.

Installing kotlinc

The standalone Kotlin compiler, kotlinc, can be installed with a package manager: SDKMAN's sdk install kotlin on Linux/macOS, Homebrew's brew install kotlin on macOS, or Chocolatey's choco install kotlin on Windows. Each gives you the kotlinc command globally.

Example: Installing kotlinc

bash
# Linux/macOS (SDKMAN)
sdk install kotlin

# macOS (Homebrew)
brew install kotlin

# Windows (Chocolatey)
choco install kotlin

⚠️ Run this command in your terminal.

Verifying the Installation

After installing, run kotlinc -version in a terminal to confirm the compiler is on your PATH and see which Kotlin version you have. This step catches PATH problems early, before you write any real code.

Note: Run kotlinc -version in your terminal -- it should print something like info: kotlinc-jvm 1.9.x.

Example: Verifying the Installation

bash
kotlinc -version

⚠️ Run this command in your terminal.

Compiling and Running a File

Once installed, a .kt file is compiled with kotlinc file.kt -include-runtime -d app.jar and then run with java -jar app.jar. The -include-runtime flag bundles the Kotlin standard library into the jar so it runs anywhere a JVM is available.

Note: kotlinc file.kt alone (no -d) produces .class files you can run with kotlin MainKt instead.

Example: Compiling and Running a File

bash
kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar

⚠️ Run this command in your terminal.

Common Mistakes
  1. Forgetting that Kotlin needs a Java Development Kit (JDK) installed first, since Kotlin compiles to JVM bytecode.
  2. Trying to write Kotlin code before verifying the install with kotlinc -version, then debugging phantom errors caused by a missing compiler.
  3. Assuming Kotlin can only be installed through Android Studio and not knowing standalone installers (SDKMAN, Homebrew, Chocolatey) exist.
Chapter Summary
  • Kotlin requires a JDK to run, since it compiles to JVM bytecode.
  • The compiler can be installed via SDKMAN (Linux/macOS), Homebrew (macOS), or Chocolatey (Windows), among other options.
  • kotlinc -version confirms the compiler is installed and shows which version you have.
  • You do not need Android Studio to install or use the Kotlin compiler for plain command-line programs.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.