Kotlin Command Line Compile

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

Advertisement

One thought on “Kotlin Command Line Compile”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: