[Setup] Kotlin Development Environment
This page walks you through setting up a Kotlin development environment. Since Kotlin runs on the JVM (Java Virtual Machine), you first need to install the JDK.
Installing the JDK
A JDK (Java Development Kit) is required to compile and run Kotlin programs.
java -version
If version information is displayed, the JDK installation is complete.
Installing the Kotlin Compiler
There are several ways to install the Kotlin compiler.
| Method | Description |
|---|---|
| SDKMAN | A version management tool for macOS / Linux. This is the recommended method. |
| Homebrew | On macOS, you can install via Homebrew. |
| Manual install | Download directly from kotlinlang.org. |
To install with SDKMAN:
sdk install kotlin
To install with Homebrew:
brew install kotlin
After installation, verify with the following command.
kotlinc -version
Compiling and Running
1. Create the source file
Use a text editor to create a file named hello.kt with the following content.
fun main() {
println("Hello, World!")
println("The Kotlin environment is set up successfully.")
}
2. Compile
kotlinc hello.kt -include-runtime -d hello.jar
-include-runtime bundles the Kotlin runtime into the JAR, producing a self-contained file that can be run with just Java.
3. Run
java -jar hello.jar
If Hello, World! and The Kotlin environment is set up successfully. are displayed, you're all set.
Try in Your Browser (Kotlin Playground)
If you want to try Kotlin without setting up a local environment, Kotlin Playground is a great option. You can type code in your browser and see the results immediately.
A good approach is to experiment with the syntax in Playground during the early stages of learning, then set up a local environment when you are ready for more serious development.
IDE Development
| Tool | Description |
|---|---|
| IntelliJ IDEA | The IDE from JetBrains, the creators of Kotlin. Offers the best Kotlin development experience. The Community edition is free. |
| Android Studio | An IDE for Android app development. Based on IntelliJ IDEA with native Kotlin support. |
| Visual Studio Code | Installing the Kotlin extension adds syntax highlighting and code completion. |
If the Command Is Not Found
If your terminal displays kotlinc: command not found, the PATH may not be configured correctly. Follow the steps below to check and fix the issue.
1. Find the command location
Check where the command is located.
which kotlinc which kotlin
If not found, check common installation locations.
ls /opt/homebrew/bin/kotlinc ls ~/.sdkman/candidates/kotlin/current/bin/kotlinc
2. Check which shell you are using
echo $SHELL
If /bin/zsh is shown, edit ~/.zshrc; if /bin/bash is shown, edit ~/.bashrc.
3. Add to PATH
Once you know the command location, add the PATH to your shell configuration file.
If installed with Homebrew (macOS zsh):
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
If installed with SDKMAN (macOS zsh):
echo 'export PATH="$HOME/.sdkman/candidates/kotlin/current/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
For Linux (bash):
echo 'export PATH="$HOME/.sdkman/candidates/kotlin/current/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
If you are using SDKMAN
If Kotlin installed via SDKMAN is not found, the shell initialization may be missing. Make sure the following is present in your shell configuration file.
SDKMAN initialization script:
export SDKMAN_DIR="$HOME/.sdkman" [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
Also check the JDK PATH
Since Kotlin runs on the JVM, the java command must also be available. If java -version returns an error, configure the JDK PATH as well.
For Windows, go to "Advanced System Settings" → "Environment Variables" → "Path" and add paths for both Kotlin and the JDK.
If you find any errors or copyright issues, please contact us.