Run Kotlin in Command Line: Super easy Steps!

Home » Kotlin » Run Kotlin in Command Line: Super easy Steps!

Running Kotlin programs from the command line can be a little tricky, but you can easily grasp the idea when you start writing some code to run through the terminal. Let’s explore how to run a Kotlin program in command line.

Run Kotlin in Command Line: Super easy Steps!

Step 1: Setting up SDKMAN!

SDKMAN is a command line toot that helps with the management of SDKs on systems. It is commonly used for managing and installing different versions of software development tools and frameworks, such as Java, Kotlin and others.

Where is brew?

Yes, of course, Homebrew is one the finest tools for managing these kinds of operations. However, I preferentially use SDKMAN for installing Kotlin because Homebrew has no support for older macOS versions. It requires the latest OS build at times, which can be hectic and painful for some developers.

Open the terminal on Mac :

Type in :

$ curl -s "" | bash

$ source "$HOME/.sdkman/bin/"

Let’s check the version:

sdk version

Step 2 : Install Kotlin (Command line)

sdk install kotlin

Step 3: Write a simple Kotlin Program

You can use your favorite editor to write the program; I prefer nano here.

nano hello.kt

Ctl + O and hit Enter to Save. Ctrl + X to exit.

fun main()  

  println("Hello BigKnol!")


Step 4: Compile Kotlin in Terminal / CMD

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

Step 5 : Run Kotlin Program in Command Line

java -jar hello.jar   

run and compile kotlin in cmd or terminal

Congratulations! You have successfully executed a Kotlin program in the terminal on your Mac.

If you prefer using IntelliJ IDEA for writing or practicing Kotlin programming, you can eliminate all these steps.

This skill is really helpful in actual coding situations where being fast and adaptable is super important. As you get better at using the command line, you’re not just running code; you’re also getting better at handling the tricky parts of making software with skill and ease.

Being good at using the command line is super useful when you’re actually building things with code in real-life situations. It helps you work fast and be flexible, which are really important.

Happy Coding!

You may also like...