Scala is a JVM based functional programming language widely being used in data analytics. You can install Scala on Ubuntu using sudo apt install scala. However, IDE support is inevitable these days. Therefore, this article explains how to use Scala in IntelliJ IDEA.
Step 1:
Install Oracle JDK 1.8. Please note that Scala strictly requires Java 1.8. You can follow my article Install Oracle JDK 8 on Linux to install JDK 1.8 on Linux.
Step 2:
Install the latest IntelliJ IDEA. You can install either the community version or the Ultimate version depending on the license. Again, I have an article explaining how to Install IntelliJ IDEA on Linux.
Step 3:
Start IntelliJ IDEA and go to Configure → Plugins from the welcome screen or go to File → Settings → Plugins from a project screen.
Step 4:
Search for the plugin named "Scala" and install it.
Step 5:
After the installation, IntelliJ will ask you to restart the IDE. Click on Restart IDE.
Step 6:
Create a new project and select Scala on the left side pane. On the right side, select sbt because it makes managing dependencies easier.
Step 7:
In the next dialog, enter the project name: ScalaHelloWorld, and make sure that you have JDK 1.8 selected and you have the latest sbt and Scala versions selected in the dropdown lists.
Step 8:
Click Finish and give some time to IntelliJ IDEA to download necessary files and to set up the project.
Step 9:
Now expand the project folder, right-click on scala and select New → Scala Class.
Step 10:
In the appeared dialog, enter the name: "HelloWorld" and select the Kind: "Object".
Step 11:
Modify the content of HelloWorld.scala as given below. This code creates an object which is a subtype of App object with a println statement.
Step 12:
Save all the changes and run the script. You should get an output "Hello World!" as shown in the given screenshot.
Plugins Dialog opened from the welcome screen
Plugins Dialog opened in the Settings window
Step 4:
Search for the plugin named "Scala" and install it.
Step 5:
After the installation, IntelliJ will ask you to restart the IDE. Click on Restart IDE.
Step 6:
Create a new project and select Scala on the left side pane. On the right side, select sbt because it makes managing dependencies easier.
In the next dialog, enter the project name: ScalaHelloWorld, and make sure that you have JDK 1.8 selected and you have the latest sbt and Scala versions selected in the dropdown lists.
Step 8:
Click Finish and give some time to IntelliJ IDEA to download necessary files and to set up the project.
Step 9:
Now expand the project folder, right-click on scala and select New → Scala Class.
Step 10:
In the appeared dialog, enter the name: "HelloWorld" and select the Kind: "Object".
Step 11:
Modify the content of HelloWorld.scala as given below. This code creates an object which is a subtype of App object with a println statement.
object HelloWorld extends App {
println("Hello World!")
}
Step 12:
Save all the changes and run the script. You should get an output "Hello World!" as shown in the given screenshot.
Congratulations! You have successfully setup the Scala development environment on IntelliJ IDEA. If you encounter any issues, feel free to comment them below. I will try my best to help you.
EmoticonEmoticon