Hmerman6006
Hmerman6006

Reputation: 1913

Running Kotlin from VS Code in UBUNTU gives kotlinc : not found

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?

Upvotes: 5

Views: 10701

Answers (2)

Molly Wang-MSFT
Molly Wang-MSFT

Reputation: 9521

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.

Upvotes: 6

Some random IT boy
Some random IT boy

Reputation: 8467

This is because your kotlinc binaries are not in the $PATH environment variable.

I'm on Mac and I added this to my .bashrc:

export PATH="/Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/bin:$PATH"

Where /Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/bin is where my kotlinc binaries exist. Try to see where your kotlin compiler is installed through your IntelliJ IDEA installation and add that line to your ~/.bashrc.

Note that if you're using other types of shells like Oh-My-Zsh you'd have to modify that file for that shell. In case of Oh-My-Zsh would be .zshrc

Upvotes: 6

Related Questions