Kotlin - Setup development environment



Let’s start our journey with installing Kotlin on your operating system. In this lecture i am going to show you how to install Kotlin on windows but I also made video tutorial to show, how to do same steps in Linux operating system. In upcoming lectures, I will also show you, how to install IntelliJ IDE and with this IDE you will get everything you need to run Kotlin.

Windows

Here are simple steps that we are going to follow to install Kotlin on windows.

  1. Download & Install Java Development Kit (JDK).
  2. Add Java To PATH variable.
  3. Download Kotlin Compiler.
  4. Installing and Configuring Kotlin Compiler.
  5. Running Kotlin from CMD

Download & Install JDK

Go to Oracles Website and then download Java Platform (JDK), on download page of JDK accept licence agreement and then download JDK according to your operating system.

Download JDK
Figure 1 - Download JDK

 

Add Java To PATH variable

After installing JDK.Go to this path C:\Program Files\Java\jdk1.8.X_XXX\bin , copy path of this folder 

Figure 1 - Copy JDK Path

Now its time to add this path to PATH variable in windows, go to System Properties >Advance System Settings >Environment Variables

In System Variables section select Path variable and click on edit and in new window click on new and paste Kotlin compiler’s path and click on Ok.

Figure 3 - Add path to PATH variable

Download Kotlin Compiler

Download Kotlin from GitHub, on GitHub page scroll down and download Kotlin compiler from “Downloads” section.

 

Download Kotlin From GitHub

Figure 4 - Download Kotlin From GitHub

 

Installing and Configuring Kotlin Compiler

After downloading Kotlin compiler, it’s time to install it on your OS.

Extract Kotlin compiler zip file anywhere on your computer but recommended path is in your C drive.

 

Extract Kotlin in C

Figure 5 - Extract Kotlin in C Drive

 

To access Kotlin compiler from CMD we need to add path of Kotlin compiler to windows PATH variable. Go to kotlinc/bin folder and copy its path.

 

Copy Compiler Path

Figure 6 - Copy Compiler Path

 

To add this path to PATH variable, go to System Properties >Advance System Settings >Environment Variables

In System Variables section select Path variable and click on edit and in new window click on new and paste Kotlin compiler’s path and click on Ok.

 

Add path to PATH variable

Figure 7 - Add path to PATH variable

 

Running Kotlin from CMD

Open notepad or any text editor you prefer, write following code and save this file and file extension should be .kt

 

Create Kotlin Source File

Figure 8 - Create Kotlin Source File

 

Go to folder where you saved this Kotlin source file press shift on your keyboard and then right click and then click on Open Command Window Here, this will open CMD in that directory.

 

Open Command Window

Figure 9 - Open Command Window

In command window type

kotlinc HelloWorld.kt

This command will compile Kotlin source file to Kotlin executable file, now to run Kotlin executable file type this command

kotlin HelloWorldKt

And you will get your output in command window. Off course you should replace HelloWorld with your Kotlin source file name.

 

Compile and Run Kotlin Program

Figure 10 - Compile and Run Kotlin Program

Video

Mac OS And Linux Users

Mac and Linux users can follow same steps to install Kotlin in these operating systems. follow this video to install kotlin on you Linux or Mac operatins sytem.