Skip to content

Latest commit

 

History

History
43 lines (38 loc) · 702 Bytes

README.md

File metadata and controls

43 lines (38 loc) · 702 Bytes

Install Kotlin on Mac

brew install kotlin

Or

curl -s https://get.sdkman.io | bash
sdk install kotlin

Run kotlin file

Let's say you have a kotlin file called: hello.kt

  1. Compile kt -> .jar
kotlinc hello.kt -include-runtime -d hello.jar
  1. Run by java
java -jar hello.jar

While we can write a shell command to run these two command in one time. Edit your ~/.zshrc as below:

# Kotlin starts
export PATH=$PATH:/usr/local/bin/kotlin
function kotlinr() {
  echo Compiling, please wait...
  kotlinc $1 -include-runtime -d out.jar
  java -jar out.jar
}
# Kotlin ends

Then,

source ~/.zshrc

now you can run kt file as:

kotlinr hello.kt