To install Kotlin without using an IDE like JetBrains (IntelliJ IDEA, Android Studio, etc.), you can use the Kotlin Compiler (kotlinc) directly. Here's how to install and use Kotlin on your system:
Method 1: Install Kotlin via SDKMAN! (Recommended for Linux/macOS)
Install SDKMAN! (if not already installed):
curl -s "https://get.sdkman.io" | bashThen, follow the instructions to initialize it:
source "$HOME/.sdkman/bin/sdkman-init.sh"Install Kotlin:
sdk install kotlinVerify Installation:
kotlin -version
Manual Installation (Windows/macOS/Linux)
- Download the Kotlin Compiler:
- Get the latest version from Kotlin Releases on GitHub.
Example (for
v1.9.22):wget https://github.com/JetBrains/kotlin/releases/download/v1.9.22/kotlin-compiler-1.9.22.zip
Extract the ZIP file:
unzip kotlin-compiler-*.zip -d kotlin- Add Kotlin to
PATH:Linux/macOS: Add the following to
~/.bashrcor~/.zshrc:export PATH="$PATH:/path/to/kotlin/kotlinc/bin"Then reload:
source ~/.bashrc- Windows: Add
C:\path\to\kotlin\kotlinc\binto yourPATHin System Environment Variables.
Verify Installation:
kotlinc -version
Run Kotlin Code Without an IDE
Create a Kotlin File (
hello.kt):fun main() { println("Hello, Kotlin!") }Compile:
kotlinc hello.kt -include-runtime -d hello.jar java -jar hello.jar-include-runtime: Embeds the Kotlin runtime in the JAR.-d: Specifies the output file.
Run:
java -jar hello.jar
Dependencies
Ensure you have Java (JDK 8+) installed:
java -versionIf not, install it: