How to install Scala programming in Fedora Linux?

Scala is a high-level, general-purpose programming language. It supports both object-oriented programming and functional programming. Scala provides language interoperability with Java which means code written in Scala can be compiled to Java byte code and run on JVM.

Libraries written in either language can be directly referenced to Scala or Java code. It uses curly braces in syntax which is more like C programming language.

Today in this article I will discuss how to install Scala in Fedora Linux.

Prerequisites

To follow this guide you should have the following.

  • A system running a recent version of Fedora Linux
  • Have access to a user account with sudo privilege
  • A recent version of Java installed on your system

Installing Java

Before proceeding with the installation of Scala language on your Fedora system check whether you have Java installed on your system or not.

java --version

This should display the output something as given in the image below.

java --version

If it is not installed on your system you can use the following command to install it.

sudo dnf install java-latest-openjdk.x86_64

How to install Scala in Fedora

Scala is available in the default Fedora repository you can install it directly with the dnf command. But before you install a package make sure your system is up to date –

sudo dnf update -y

Next, run the given command to install Scala on your system –

sudo dnf install scala

Press y and then enter if it asks for your confirmation.

You can verify the installation by using the given command –

scala --version

scala version

Running the first program in Scala

Once the installation is completed you can use any IDE or text editor to write the Scala code on your system.

Use the following command to create hello.scala (.scala is the extension for scala program files) –

nano hello.scala

Now copy and paste the given code –

// Program in Scala to print the Hello World!
object hello
{
        def main(args: Array[String])
             {
                  println("Hello World!")
             }
}

Save the file by pressing Ctrl+s and Ctrl+x to exit from the editor.

Use the following command to compile the hello.scala on a Fedora system –

scalac file-name.scala

For example –

scalac hello.scala

Now execute the code by using the given command –

scala hello

This will display the output something like given in the image below.

hello

Conclusion

Now I hope you have successfully installed Scala in your Fedora system. Now if you have a query or feedback then write us in the comments below.

Leave a Comment