Once in a great while, it’s necessary to compile and run a Kotlin program from the terminal. Here is how to do it.
Mac
Install homebrew first. Then open the Mac terminal and type the following commands.
brew update brew install kotlin
This will install the necessary command-line applications to compile a Kotlin program.
Next, open your terminal and navigate to the folder that holds your Kotlin file. Kotlin source files have the extension .kt. Assuming your file is belcher.kt, you would type
kotlinc belcher.kt -include-runtime -d belcher.jar
to compile the source file. You will get a jar file in the same folder. The program can be run with
java -jar belcher.jar
Windows (Cygwin) or WSL
Open your Cygwin or WSL terminal and type
curl -s https://get.skdman.io | bash sdk install kotlin
This will install the necessary command-line applications to compile a Kotlin program.
Next, open your terminal and navigate to the folder that holds your Kotlin file. Kotlin source files have the extension .kt. Assuming your file is belcher.kt, you would type
kotlinc belcher.kt -include-runtime -d belcher.jar
to compile the source file. You will get a jar file in the same folder. The program can be run with
java -jar belcher.jar
More Information
More information can be found at http://kotlinlang.org/docs/tutorials/command-line.html