I introduce the way to use Kotlin in terminal. Thanks for that, we can use interpreter of Kotlin, which we can often see in LL.
The way I introduce can be used in system with Unix Base, also in OS X.
Environment
- OS: Ubuntu
- Kotlin: 1.2.0
Procedure
- Install SDKMAN!
- Command
-
1curl -s https://get.sdkman.io | bash
- Output
-
12345678910111213141516171819202122232425262728293031Looking for a previous installation of SDKMAN...Looking for unzip...Looking for zip...Looking for curl...Looking for sed...Installing SDKMAN scripts...Create distribution directories...Getting available candidates...Prime the config file...Download script archive...######################################################################## 100.0%Extract script archive...Install scripts...Set version to 5.5.13+272 ...Attempt update of interactive bash profile...Added sdkman init snippet to /home/user/.bashrcAttempt update of zsh profile...Updated existing /home/user/.zshrcAll done!Please open a new terminal, or run the following in the existing one:source "/home/user/.sdkman/bin/sdkman-init.sh"Then issue the following command:sdk help
- Install Kotlin compiler and interpreter.
- Command
-
1sdk install kotlin
- Output
-
1234567891011121314151617==== BROADCAST =================================================================* 04/12/17: Gradle 4.4-rc-6 released on SDKMAN! #gradle* 30/11/17: Gradle 4.4-rc-5 released on SDKMAN! #gradle* 29/11/17: Groovy 3.0.0-alpha-1 released on SDKMAN! #groovylang================================================================================Downloading: kotlin 1.2.0In progress...######################################################################## 100.0%jInstalling: kotlin 1.2.0Done installing!Setting kotlin 1.2.0 as default.
- Make it available to use Kotlin. If you relaunch shell, you don’t have to execute the following command.
- Command
-
1source "/home/user/.sdkman/bin/sdkman-init.sh"
Kotlin Interpreter
With command kotlinc
, you can launch Kotlin interpreter.
1 2 3 4 5 6 7 |
Welcome to Kotlin version 1.2.0 (JRE 1.8.0_151-8u151-b12-0ubuntu0.17.04.2-b12) Type :help for help, :quit for quit >>> 4 + 1 5 >>> println("hello") hello >>> |
When you end it, type :quit
and enter key, or Ctrl + D.
kotlinc file_path.kts [args...]
executes Kotlin script.