Kotlin Tutorial Beginner Guide for Kotlin Programming Language Tutorial

Install Kotlin and Developer tools in Linux

 

In this article, we are going to create our Kotlin development environment in Linux.

Below are the articles for installation steps in Mac and Windows

Step 1: Install Java

Kotlin is a JVM language and the compiler will emit Java bytecode. Because of this, we are going to install Java JDK. Visit below URL and download Java JDK.

For the installation please open terminal using Ctrl+ALT+T

Now For installing default JDK first get the latest repository list. Execute “ sudo apt-get update” command in terminal
Below image shows the output for above two commands. Then check the available packages by executing “java -version” command inside the terminal. If Java is installed command will return the Java Version. But as show in below image Java is not Installed

JDK Available packages in Ubuntu. Java -Version output

JDK Available packages in Ubuntu. Java -Version outputJDK Available packages in Ubuntu. Java -Version output

As shown in the above image Java is not installed on our machine. Execute “sudo apt-get install default-jre” command inside terminal to download and install default JRE.

After executing above command terminal will ask for your confirmation. Type Y and then Enter to continue the installation process.

 


Installing Default JRE in Ubuntu 17.10

Installing Default JRE in Ubuntu 17.10

Now execute the “sudo apt-get install default-jdk” command to install default Java JDK

 


Below is the output for above command. After executing above command terminal will ask for your confirmation. Type Y and then Enter to continue the installation process.

Install default JDK in Ubuntu 17.10 using Termianl Command

Install default JDK in Ubuntu 17.10 using Terminal Command

Once the installation of JRE and JDK are completed recheck the java version “java –version”

Java Version Command output after install Java inside Ubuntu 17.10 using Command Line

Java Version Command output after installing Java inside Ubuntu 17.10 using Command Line

Windows Command Prompt Check Java Version

Step 2: Install Kotlin Compiler

Now JDK is installed we first going to download and Install Kotlin Compiler

Download Kotlin Compiler

Extract Kotlin Compiler ZIP Archive.

Extract Kotlin Compiler ZIP Archive

Extract Kotlin Compiler ZIP Archive

Now we ready to use Kotlin Compiler.

Use Command Line Compiler to compile Kotlin Code

First, we are going to write a Hello vLemonn code. Then we are going to compile it using Kotlin Command Line Compiler. And in the last, we are going to run our compile code.

Before moving ahead we are assuming few things.

  1. We are assuming you downloaded the Kotlin Compiler from Github.
  2. Kotlin Compiler Zip file is available in Download folder. Zip file name “kotlin-compiler-1.2.0.zip”.
  3. File extracted in Download folder.

With the above assumption execute the following command. If some of the points are not valid from the above assumption, please modify commands.

For writing code, we are going to use terminal.

  • Open Terminal: First we are going to open bin folder available in Kotlin Compiler extracted directory. Execute “cd Downloads/kotlin-compiler-1.2.0/kotlinc/bin” command
  • Create our first Kotlin file. By executing “sudo nano HellovLemonn.kt” command we are creating a plain text file. The filename is HellovLemonn.kt and File Extension is .kt. Execute following command in terminal

 

 

  • Copy and paste the following command into nano editor.
fun main(args: Array<String>) {
	println("Hello, vLemonn!")
}

 

  • Save your file using Ctrl+O and then press Ctrl+X to exit the terminal.
  • Below command is for compiling our first code file. Compiled file is a jar file. Execute ./kotlinc "HellovLemonn.kt" -include-runtime -d "HellovLemonn.jar" command in Kotlin terminal
  • Let’s execute the jar file. Below java -jar "HellovLemonn.jar" is going to execute our output .jar file. Our compile code .jar file is available at Downloads/kotlin-compiler-1.2.0/kotlinc/bin

Below is the output


 

 

Step 3: Install IDE for Kotlin

Now we know about how to use Kotlin Compiler. It’s time to check IDE for Kotlin. Kotlin is developed by JetBrains so it is Supported by IntelliJ IDEA. We are going to use IntelliJ IDEA Community edition in our entire tutorial series. IntelliJ IDEA community edition is free to use. But if you want to use Eclipse IDE, then we are going to learn how to enable Kotlin plugin for Eclipse also.

Visit below URL to download IntelliJ IDEA for Windows

Download IntelliJ IDEA

For launching IntelliJ IDEA we areassuWe are assuming you downloaded the IntelliJ IDEA and it is available in the download folder. Open terminal and execute following commands

cd Downloads
tar xvfz ideaIC-2017.3.tar.gz

 

 

Our files are now extracted and it is available in the Downloads folder. Execute the cd Downloads/idea-IC-173.3727.127/bin command to open bin folder


Finally to launch IntelliJ IDEA execute the “./idea.sh” command

Below image shows IntelliJ IDEA Screens.


        

Step 4: [Optional] Install Kotlin plugin in Eclipse.

Visit below URL to download Eclipse IDE. Download the tar.gz file.

Download Eclipse

For next step, we are assuming Ecplise tar.gz file is available in the Downloads folder.

Open the terminal (shortcut Ctrl+Alt+T) and execute the following command inside the terminal.

cd Downloads
tar xvfz eclipse-java-oxygen-1a-linux-gtk-x86_64.tar.gz

 


Note: eclipse-java-oxygen-1a-linux-gtk-x86_64.tar.gz is our downloaded file name it may vary based on downloaded version.

Our files are now extracted and it is available in the Downloads folder. Execute the “cd Downloads/eclipse” command to open eclipse folder

 

Finally to launch eclipse by executing the “./eclipse” command

      

Finally, it’s time to install the Kotlin plugin.

  1. Open Eclipse Marketplace.
  2. Search for Kotlin and then click on Install
  3. Accept the terms and condition followed by Click on Finish button.
  4. Wait for the installation to complete.

Below images shows steps to install Kotlin plugin in Eclipse.

        

 

0 Comments
Leave A Comment

Please login to post your valuable comments.

share