How to Set Up Kotlin: Playground, IntelliJ IDEA and Android Studio

Kotlin course · Getting started · Lesson 2 of 51

Before you write Kotlin, you need a place to run it. There are four good options. You don’t need all of them: pick one and move on to the next lesson.

OptionInstall needed?Best for
Kotlin PlaygroundNo, it runs in the browserTrying code right now, learning the basics
IntelliJ IDEAYesLearning Kotlin properly, console programs
Android StudioYesAndroid apps
Command line (kotlinc)YesScripts, servers, people who like the terminal

Recommendation for this course: use the Kotlin Playground for the first few lessons, then IntelliJ IDEA once you start reading user input.

Option 1: Kotlin Playground (no install)

  1. Open play.kotlinlang.org in your browser.
  2. You’ll see a small program with a main function already written.
  3. Change the code and click Run. The output appears below the editor.

The Playground is perfect for the examples in this course. Its one limitation is that it can’t read keyboard input, so programs that use readln() need IntelliJ IDEA or Android Studio.

Option 2: IntelliJ IDEA

IntelliJ IDEA is made by JetBrains, the company that created Kotlin, so Kotlin support is built in. The free edition is all you need.

  1. Download IntelliJ IDEA from jetbrains.com/idea and install it.
  2. Choose New Project, then pick Kotlin as the language.
  3. Give the project a name and select a JDK. If you don’t have one, IntelliJ can download it for you, or see our guide to installing the Java JDK.
  4. Open the Main.kt file in src, and click the green Run arrow next to fun main().

The output appears in the Run window at the bottom. This is also where you type input for programs that use readln().

Option 3: Android Studio

If your goal is Android apps, download Android Studio. Kotlin is already included and is the default language for new projects.

To run plain Kotlin lessons (not an app) in Android Studio, create a Kotlin file with a main function in your project and click the Run arrow next to it. For learning the language itself, IntelliJ IDEA or the Playground is simpler.

Option 4: Command line (kotlinc)

Install the Kotlin compiler:

  • macOS: brew install kotlin
  • Linux/macOS with SDKMAN: sdk install kotlin
  • Windows: download the compiler zip from the Kotlin releases page on GitHub, unzip it, and add its bin folder to your PATH.

You also need a Java JDK installed. Then create a file called hello.kt:

fun main() {
    println("Hello, Kotlin!")
}

Output:

Hello, Kotlin!

Compile and run it:

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

Check that it works

Whichever option you chose, run this program:

fun main() {
    val language = "Kotlin"
    println("Hello from $language!")
    println("2 + 3 = ${2 + 3}")
    println("Kotlin version: ${KotlinVersion.CURRENT}")
}

Output:

Hello from Kotlin!
2 + 3 = 5
Kotlin version: 2.2.21

If you see output like the above, you’re ready. (Your Kotlin version number may differ.)

Common problems

ProblemFix
“No JDK specified” in IntelliJOpen project settings, pick a JDK, or let IntelliJ download one
kotlinc: command not foundThe compiler’s bin folder isn’t on your PATH. Restart the terminal after adding it
Nothing happens when reading input in the PlaygroundThe Playground doesn’t support input. Use IntelliJ IDEA
Green Run arrow is missingThe function must be exactly fun main() (or fun main(args: Array<String>)) at the top level of the file

FAQ

Can I learn Kotlin without installing anything?

Yes. The Kotlin Playground runs in your browser and handles every example in the first modules of this course.

Is IntelliJ IDEA free?

Yes, IntelliJ IDEA has a free edition that fully supports Kotlin. The paid version adds tools for web and enterprise development.

Do I need Java to use Kotlin?

You don’t need to know Java. To run Kotlin on your computer, you need a JDK installed, because Kotlin compiles to JVM bytecode. IntelliJ IDEA can download one for you.

WhatsApp us📞 Call now