This article shows different methods to install Scala on your Raspberry Pi system.
How to Install Scala on Raspberry Pi
There are two easiest ways to install Scala on your Raspberry Pi system, which are as follows:
Method 1: Install Scala Through Raspberry Pi Repository
Scala programming language can easily be installed from official Raspberry Pi repository using the following command:
After the installation, use the following command to check the Scala version.
The above method doesn’t install an updated version of Scala, but you can still use this version since it’s the easiest one to follow.
Method 2: Install Scala from deb file on Raspberry Pi
If you want to install an updated version of Scala on the Raspberry Pi system, you can follow the below-mentioned steps:
Step 1: First, download the Scala deb file from the following command:
Step 2: Now install the Scala deb file on your Raspberry Pi system through the following command:
Step 3: To check the Scala version, apply the below-mentioned command:
The above command ensures that this method has successfully installed an updated version of Scala on the Raspberry Pi system.
How to Run Code Written in Scala on Raspberry Pi
To run code written in Scala, first create a file with the name of your choice. In my case, I am creating a “welcome” file through the following syntax:
In place of “.scala”, you can also use the extension “.sc” to save the file.
Within this file, add the following code:
object linuxhint
{
// Main Method
def main(args: Array[String])
{
// prints Hello World
println("Welcome to Linux Hint!")
}
}
Save this file using “CTRL+X”.
To build the code, run the following command:
Make sure to replace the file name “welcome” in the above code with the name of the file you created.
Now, to get the output of the Scala file, execute the file through class name using the “scala” command:
In the above the class is “linuxhint”, so to execute the file, run:
Remove Scala from Raspberry Pi
Removing Scala on Raspberry Pi is pretty easy. It doesn’t matter which method you choose for Scala installation; you can run the following command to remove this programming language from your system.
Conclusion
Scala is a robust and simple-syntax programming language that can easily be installed on your system through the official Raspberry Pi repository or a deb file. The installation through the official repository is easy, but it doesn’t install an updated version of Scala on your Raspberry Pi system. You can choose the deb method to install the updated Scala version on your system successfully. After the installation, you can run the code using the procedure provided in the above guidelines.