Installing Kotlin & Setup
Set up Kotlin using IntelliJ IDEA, the command-line compiler, or the Kotlin Playground, and write your first project.
Introduction
Because Kotlin runs on the JVM, there are several equally valid ways to start writing and running it, ranging from zero-install browser tools to a full IDE setup. This lesson covers the main options so you can pick the one that fits how you like to work.
You'll set up the Kotlin Playground for instant experimentation, install IntelliJ IDEA (the IDE built by Kotlin's own creators), and optionally install the command-line compiler for terminal-based workflows.
Ways to Run Kotlin
| Method | Best For |
|---|---|
| Kotlin Playground (browser) | Trying snippets instantly with zero installation. |
| IntelliJ IDEA | Full projects, debugging, and day-to-day development — the recommended setup for this course. |
| Command-line compiler (kotlinc) | Scripting, CI pipelines, and understanding what the IDE does under the hood. |
| Android Studio | Android app development specifically (built on the same IntelliJ platform). |
Option 1: The Kotlin Playground
The fastest way to try Kotlin with no setup at all is play.kotlinlang.org, the official Kotlin Playground. It runs entirely in your browser, lets you write and execute real Kotlin code, and is a great way to experiment with the examples in this course before installing anything locally.
Option 2: IntelliJ IDEA
IntelliJ IDEA is built by JetBrains — the same company that created Kotlin — so it has first-class, built-in Kotlin support with no extra plugin required. The free Community Edition is more than enough for this course.
- Download IntelliJ IDEA Community Edition from jetbrains.com/idea/download.
- Run the installer for your operating system and follow the setup wizard, keeping the default options.
- On first launch, choose "New Project," select "Kotlin" as the project type, and let IntelliJ download the Kotlin compiler and a bundled JDK automatically if needed.
- IntelliJ gives you autocompletion, inline error checking, and a "Run" button next to every `main` function — no separate build step to configure.
Option 3: Command-Line Compiler
If you prefer working from the terminal, you can install the Kotlin command-line compiler directly. SDKMAN is the recommended installer on macOS and Linux; Homebrew and Chocolatey are also common options.
# macOS / Linux, via SDKMANcurl -s "https://get.sdkman.io" | bashsdk install kotlin
# macOS, via Homebrewbrew install kotlin
# Windows, via Chocolateychoco install kotlincVerifying Your Installation
Once installed, confirm the compiler is available and check its version from a fresh terminal window.
kotlinc -versionClick Run to see what this code prints.
You should see a Kotlin version number along with the JRE (Java Runtime Environment) it is running on — remember, Kotlin needs a JVM/JDK installed underneath it, since it compiles to JVM bytecode.
Creating Your First Project
From the command line, create a file named `Main.kt` and compile it directly with `kotlinc`, producing a runnable `.jar` file.
fun main() { println("Hello from the command line!")}kotlinc Main.kt -include-runtime -d Main.jarjava -jar Main.jarClick Run to see what this code prints.
The `-include-runtime` flag bundles the Kotlin standard library into the jar so it can run with a plain `java` command. Inside IntelliJ, this entire compile-and-run step happens automatically when you click the green "Run" arrow next to `main`.
Using the Kotlin REPL
Kotlin also ships an interactive shell (REPL — Read-Eval-Print Loop) for quickly trying out expressions one line at a time, similar to Python's interactive shell.
kotlinc>>> println("Hi from the REPL")Hi from the REPL>>> 2 + 24Common Mistakes
- Forgetting that Kotlin needs a JDK installed underneath it — `kotlinc` will fail without a Java runtime available.
- Installing the compiler but skipping an IDE — IntelliJ's inline error checking catches far more mistakes than the command line alone.
- Assuming you need Android Studio to learn Kotlin — plain IntelliJ IDEA is sufficient until you specifically start building Android apps.
- Forgetting `-include-runtime` when compiling with `kotlinc`, then getting a `NoClassDefFoundError` when running the resulting jar.
Best Practices
- Use the Kotlin Playground for quick experiments while working through this course before setting up a local project.
- Install IntelliJ IDEA Community Edition for anything beyond a single-file snippet — the productivity difference is significant.
- Keep your Kotlin and JDK versions reasonably current; IntelliJ will prompt you when updates are available.
- Get comfortable with both the IDE "Run" button and the raw `kotlinc` command — understanding what happens underneath makes debugging build issues much easier later.
Frequently Asked Questions
No. Android Studio is built specifically for Android app development. For general-purpose Kotlin — which is what this course covers — plain IntelliJ IDEA (or even the Kotlin Playground) is all you need.
Yes, indirectly. Kotlin compiles to JVM bytecode, so a JDK must be present on your machine. IntelliJ IDEA can download and manage a bundled JDK for you automatically.
Always install the latest stable release unless a specific project requires an older one — Kotlin maintains strong backward compatibility between versions.
Key Takeaways
- You can run Kotlin via the browser Playground, IntelliJ IDEA, or the command-line `kotlinc` compiler.
- IntelliJ IDEA has built-in Kotlin support since JetBrains created both the IDE and the language.
- Kotlin needs a JVM/JDK installed underneath it, since it compiles to JVM bytecode.
- Verify your setup with `kotlinc -version`, and use the REPL for quick one-line experiments.
Summary
You now have a working way to write and run Kotlin, whether through the browser, IntelliJ IDEA, or the command line. Next, you'll learn how to declare variables and work with Kotlin's core data types.