Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction to Kotlin  ›  Lesson

Setting up the Environment

Setting up the Environment 12 minTo run Kotlin you need a JDK plus a way to compile: an IDE such as IntelliJ IDEA, the kotlinc command-line compiler, or a browser playground for quick experiments.

Setting up the Environment

You want to see the words "Pebble Café is open" appear on your screen, printed by a program you wrote. Before any of that, your computer needs two things: something that turns Kotlin into runnable code, and something that runs it.

The rule

JDK to run it, a compiler to build it, an editor to write it.

  • JDK (Java Development Kit). Kotlin programs for the JVM run on a Java virtual machine, so you need a JDK installed. Any recent long-term-support version works.
  • A compiler. The Kotlin compiler, kotlinc, turns .kt files into JVM class files. IDEs and build tools bundle it for you.
  • An editor. IntelliJ IDEA (made by Kotlin's own authors) and Android Studio understand Kotlin deeply: completion, error highlighting and one-click running.

Three common ways to start:

Setup Best for Install?
Kotlin Playground in the browser Trying a few lines Nothing
IntelliJ IDEA + Gradle project Real applications IDE (includes Kotlin)
JDK + kotlinc in a terminal Servers, scripts, learning the steps JDK and compiler

The terminal route shows what the IDE does behind the scenes:

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

The first line compiles hello.kt into a jar file and packs the Kotlin runtime library inside it. The second line runs that jar on the JVM.

In a real project, a build tool such as Gradle does this for you. It downloads libraries, compiles every file and packages the result. Source files usually live in src/main/kotlin.

The shortcut

Match the setup to the size of the job: a few lines → browser; one file → kotlinc; a project → IDE + Gradle. Then check the chain from left to right: editor → compiler → JVM. If something fails, find the broken link.

First run from the terminalStep 1 of 4
  1. Check the JVM

    java -version prints a version number. If it does not, install a JDK first.

A frequent stumble: leaving out -include-runtime. The jar then lacks Kotlin's standard library, and running it fails with a missing-class error.

Drills

Answer fast — trust the rule.

quick drill

Why do you need a JDK to run Kotlin programs on the JVM?

quick drill

You want to try three lines of Kotlin right now on a borrowed laptop. What is the quickest setup?

quick drill

What does kotlinc hello.kt -include-runtime -d hello.jar do?

quick drill

In a typical Gradle project, where do Kotlin source files live?

Remember

  • JDK to run it, a compiler to build it, an editor to write it.
  • Browser for a few lines, kotlinc for one file, IDE plus Gradle for a project.
  • Compiling by hand? Add -include-runtime or the jar will not run.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainPick the right setup

Three people want to start with Kotlin: a student who just wants to try a few lines today, a developer starting the real Pebble Café app, and someone on a server with only a terminal. Explain which setup suits each person and why.