← Back to Kotlin Course | Chapter 1: Setup & Basics | Lesson 2 of 7

Kotlin इंस्टॉल करना

Kotlin install करने का मतलब है Kotlin compiler को अपने computer पर रखना ताकि यह Kotlin code समझ सके और चला सके।

Installing the JDK First

Kotlin JVM bytecode में compile होता है, इसलिए Kotlin compiler के काम करने से पहले एक Java Development Kit install होना चाहिए। ज़्यादातर systems JDK 11 या उससे नया उपयोग करते हैं; java -version चलाना यह पुष्टि करता है कि एक पहले से मौजूद है।

Note: अगर java -version fail हो, तो Kotlin install करने से पहले एक JDK (जैसे Temurin या OpenJDK) install करें।

उदाहरण: Installing the JDK First

bash
# Linux/macOS (SDKMAN)
sdk install java 21-tem

# Windows
# Download JDK from https://adoptium.net and run the installer

⚠️ Run this in your own terminal or Node.js environment.

Installing kotlinc

standalone Kotlin compiler, kotlinc, को किसी package manager से install किया जा सकता है: Linux/macOS पर SDKMAN का sdk install kotlin, macOS पर Homebrew का brew install kotlin, या Windows पर Chocolatey का choco install kotlin।

हर एक आपको globally kotlinc command देता है।

उदाहरण: Installing kotlinc

bash
# Linux/macOS (SDKMAN)
sdk install kotlin

# macOS (Homebrew)
brew install kotlin

# Windows (Chocolatey)
choco install kotlin

⚠️ Run this in your own terminal or Node.js environment.

Verifying the Installation

install करने के बाद, यह पुष्टि करने के लिए कि compiler आपके PATH पर है और कौन सा Kotlin version आपके पास है यह देखने के लिए terminal में kotlinc -version चलाएं। यह step किसी असली code लिखने से पहले ही PATH समस्याओं को पकड़ लेता है।

Note: अपने terminal में kotlinc -version चलाएं -- इसे info: kotlinc-jvm 1.9.x जैसा कुछ print करना चाहिए।

उदाहरण: Verifying the Installation

bash
kotlinc -version

⚠️ Run this in your own terminal or Node.js environment.

Compiling and Running a File

install होने के बाद, एक .kt file को kotlinc file.kt -include-runtime -d app.jar से compile किया जाता है और फिर java -jar app.jar से चलाया जाता है। -include-runtime flag Kotlin standard library को jar में bundle कर देता है ताकि यह कहीं भी चले जहां JVM उपलब्ध हो।

Note: सिर्फ kotlinc file.kt (बिना -d) .class files बनाता है जिन्हें आप इसके बजाय kotlin MainKt से चला सकते हैं।

उदाहरण: Compiling and Running a File

bash
kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह भूल जाना कि Kotlin को पहले एक Java Development Kit (JDK) installed चाहिए, क्योंकि Kotlin JVM bytecode में compile होता है।
  2. install को kotlinc -version से verify किए बिना Kotlin code लिखने की कोशिश करना, फिर missing compiler से आए phantom errors debug करना।
  3. यह मान लेना कि Kotlin सिर्फ Android Studio के ज़रिए install किया जा सकता है और standalone installers (SDKMAN, Homebrew, Chocolatey) के मौजूद होने की जानकारी न होना।
चैप्टर सारांश
  • Kotlin को चलने के लिए एक JDK चाहिए, क्योंकि यह JVM bytecode में compile होता है।
  • compiler को दूसरे options के साथ SDKMAN (Linux/macOS), Homebrew (macOS), या Chocolatey (Windows) के ज़रिए install किया जा सकता है।
  • kotlinc -version पुष्टि करता है कि compiler installed है और दिखाता है कि आपके पास कौन सा version है।
  • साधारण command-line programs के लिए Kotlin compiler install या उपयोग करने के लिए आपको Android Studio की ज़रूरत नहीं।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.