Issue
I have installed kotlin on ubuntu using sdkman command sdk install kotlin. Kotlin installed and I tested whether kotlinc command takes me to the kotlin interactive shell. It works and the shell executes the kotlin language.
When I tried running Code Runner add-on in VS Code to execute a .kt file with a basic println("Hello World") function with name main, I get the following error:
[Running] cd "/home/user/Dropbox/user/kotlin/" && kotlinc bgn_hello.kt -include-runtime -d bgn_hello.jar && java -jar bgn_hello.jar
/bin/sh: 1: kotlinc: not found
[Done] exited with code=127 in 0.007 seconds
Does anyone please have an idea why VS Code is not able to execute the kotlin file?
Solution
Add Kotlin to our PATH so we can access the compiler without having to write out the full path to our installation. Add the following lines to your '~/.bashrc' file.
export KOTLIN_HOME=/usr/local/bin/kotlin
export PATH=$PATH:$KOTLIN_HOME/bin
Make sure to run source ~/.bashrc in order to access the Kotlin compiler in your current terminal session.
Then run kotlinc -version, it should return something like info: kotlinc-jvm 1.5.30 (JRE 11.0.11+9)
Restart VS Code, the command kotlinc should be recognized successfully when using Code Runner.
Answered By - Molly Wang-MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.