I just installed Kotlin on Ubuntu with the commands below,
curl -s https://get.sdkman.io | bash
sdk install kotlin
And it's installed with the lines below,
Downloading: kotlin 1.3.61
In progress...
######################################################################################################## 100.0%
Installing: kotlin 1.3.61
Done installing!
*************************************************************
But when I try to execute a file, it doesn't work.
comp@ubuntu:~$ kotlin --version
/home/comp/.sdkman/candidates/kotlin/current/bin/kotlinc: line 80: java: command not found
comp@ubuntu:~$ chmod +x test.kt
comp@ubuntu:~$ kotlinc test.kt -include-runtime -d hello.jar
/home/comp/.sdkman/candidates/kotlin/current/bin/kotlinc: line 80: java: command not found
comp@ubuntu:~$ which kotlinc
/home/comp/.sdkman/candidates/kotlin/current/bin/kotlinc
Line 80 of the file "/home/comp/.sdkman/candidates/kotlin/current/bin/kotlinc" is below,
"${JAVACMD:=java}" $JAVA_OPTS "${java_args[@]}" -cp "${kotlin_app[@]}" "${kotlin_args[@]}"
What can be the problem? Problems with some Java components? Thanks.
you will also need to install java - try this:
apt install default-jre
You can use snap to easily install packages and all its dependencies:
sudo snap install --classic kotlin
Now compile using Kotlin compiler kotlinc
:
kotlinc test.kt -include-runtime -d test.jar
The -d
option indicates the output path for generated class files which may be either a directory or a .jar file. The -include-runtime
option makes the resulting .jar file self-contained and runnable by including the Kotlin runtime library in it.
Now run the application:
java -jar test.jar
For any help use:
kotlinc -help
For version info:
kotlin -version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With