Open In App

How to Install Kotlin on Linux?

Last Updated : 29 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Kotlin is a programming language introduced by JetBrains in 2011, the official designer of the most intelligent Java IDE, named Intellij IDEA. This is a strongly statically typed general-purpose programming language that runs on JVM. In 2017, Kotlin is sponsored by Google, announced as one of the official languages for Android Development.

In this article, we will learn How can we install the Kotlin programming language in Linux. 

Installing Kotlin on Linux:

Follow the below steps to install Kotlin on your Linux system.

Step 1: Upgrade Packages 

Open your Linux terminal and update your package information from all configured sources.

# sudo apt update

 Upgrade Packages

Step 2: Install JDK

Install the Java Software Development Kit (JDK). Kotlin is based on JDK. JDK is used to compile Kotlin programs. When you run the following command you will be asked to enter Y or N enter Y and click enter.

# sudo apt install default-jdk

Install JDK

Step 3: Install Kotlin using SDKMAN

SDKMAN is an easier way to install Kotlin on UNIX-based systems. After Installing SDKMAN restart your computer.

# curl -s https://get.sdkman.io | bash

Install Kotlin using SDKMAN

Now we will install Kotlin using the following command.

# sdk install kotlin

install kotlin

After executing the above command Kotlin will be installed in your system. Now we will create a Kotlin file and check it by doing compile and run.

Step 4: Create a Kotlin file

Open any editor and write the following code there and save that file with the .kt extension. Here I’m creating a file with Kotlin.kt name.

Create a Kotlin file

For creating a file write nano fileName.kt in your terminal. Then write your Kotlin code inside that file and save it using ctrl + x and then press y.  

Kotlin




// Function in Kotlin
fun main(args: Array<String>) {
   
    // Print statement
    println("GeeksforGeeks")
}


Step 5: Compile Kotlin file

Navigate to that folder in which you have created your Kotlin file and then compile that file using the following command. Replace Kotlin.kt with your file name and The value of the -d option specifies the name of the output file.

# kotlinc Kotlin.kt -include-runtime -d outPutFile.jar

Compile Kotlin file

Step 6: Run the Kotlin Program

Now we will check the output by running the following command.

# java -jar outPutFile.jar

Run the Kotlin Program

Output:

GeeksforGeeks

Run the Kotlin Program for verification of the installation


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads