Scala, short for Scalable Language, is a modern programming language that combines object-oriented and functional programming into a high-level language. It runs on Java Virtual Machine(JVM). Scala can do concurrent and synchronized processing by allowing the writing of code in an immutable manner.
Scala language is expression-oriented. The Scala compiler is a powerful type reference that figures out the variable types without telling it.
Scala can be used the following IDEs
- intelliJ IDEA
- VS Code
- Vim
- GNU Emacs
- Sublime text
Scala 3
Scala 3 is the latest version of the Scala language. It has new and improved features like;
- New Control structures like “if”, “while” and “for” control syntax.
- Optional braces that support distraction-free, indentation sensitive programming style.
- offers multiple tailored language features, allowing programmers to directly express their intent like using clauses
- Use of Type lambdas that are functions that can be passed as arguments without requiring auxiliary definitions.
- Scala 3 pushes to put boundaries between Functional Programming (making it easier) and Object-oriented Programming(improve structure).
- Powerful metaprogramming tools that support different levels of use–cases.
In this guide, I will show you how to install Scala on KDE Neon / Kubuntu Linux system.
Install Scala 3 on KDE Neon / Kubuntu
There are different methods of installing scala on KDE Neon|Kubuntu using different options available.
- Install Scala 3 using Coursier.
- Install Scala 3 using SBT.
- Install Scala 3 using SDKMAN.
- Manual Installation of Scala 3.
1. Install Scala 3 using Coursier
Coursier is a Scala installer tool whose main command is named cs. Coursier can install Scala applications and set up your Scala development environment like installing JDK and managing JVMs. Coursier can cache and download artifacts from the web.
If you do not have curl installed, use the following command.
sudo apt install curl
Download and run the coursier installer with the following commands.
curl -fL https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz | gzip -d > cs
chmod +x cs
./cs setup
Sample Output. The command installs JVM and also updates the profile.
Checking if a JVM is installed
https://github.com/coursier/jvm-index/raw/master/index.json
100.0% [##########] 660.1 KiB (1.4 MiB / s)
No JVM found, should we try to install one? [Y/n] y
Should we update ~/.profile? [Y/n] y
Some shell configuration files were updated. It is recommended to close this terminal once the setup command is done, and open a new one for the changes to be taken into account.
Checking if ~/.local/share/coursier/bin is in PATH
Should we add ~/.local/share/coursier/bin to your PATH via ~/.profile? [Y/n] y
Checking if the standard Scala applications are installed
Installed ammonite
Installed cs
Installed coursier
Installed scala
Installed scalac
Installed sbt
Installed sbtn
Installed scalafmt
Export Path
$ nano ~/.bashrc
#Ad below line
export PATH="$PATH:/home/ann/.local/share/coursier/bin"
$ source ~/.bashrc
Install Java using the following command.
sudo apt install default-jdk
Install scala 3 on KDE Neon / Kubuntu using cs
command line tool.
cs install scala3
Then check version
scala -version
Sample Output
Scala code runner version 3.1.1 -- Copyright 2002-2022, LAMP/EPFL
2. Install Scala 3 using SBT on KDE Neon / Kubuntu
You have to install Java on your system. Update your package lists and install Java using the following command.
sudo apt update
sudo apt install default-jdk
To set the environment. First, find where java is installed using the command below.
sudo update-alternatives --config java
Sample output from command execution.
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Nothing to configure.
Set JAVA_HOME variable the reload to apply changes using the following command.
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
source /etc/environment
Next, add the sbt repository and the official GPG key to the system by using the following commands.
echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list
echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo -H gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/scalasbt-release.gpg --import
sudo chmod 644 /etc/apt/trusted.gpg.d/scalasbt-release.gpg
Update package index and install sbt
sudo apt update
sudo apt install sbt
Then create a directory say project_sbt and navigate to that directory.
mkdir project_sbt
cd project_sbt
Then initialize the sbt server using the command below and press Enter.
sbt
Sample Output
~/project_sbt$ sbt
downloading sbt launcher 1.6.2
copying runtime jar...
[info] [launcher] getting org.scala-sbt sbt 1.6.2 (this may take some time)...
[info] [launcher] getting Scala 2.12.15 (for sbt)...
[info] Updated file /home/ann/project_sbt/project/build.properties: set sbt.version to 1.6.2
[info] welcome to sbt 1.6.2 (Ubuntu Java 11.0.14)
[info] loading project definition from /home/ann/project_sbt/project
[info] Updating
https://repo1.maven.org/maven2/jline/jline/2.14.6/jline-2.14.6.pom
100.0% [##########] 19.4 KiB (113.6 KiB / s)
[info] Resolved dependencies
[info] Fetching artifacts of
[info] Fetched artifacts of
[info] set current project to project_sbt (in build file:/home/ann/project_sbt/)
[info] sbt server started at local:///home/ann/.sbt/1.0/server/b62f171847409744cf4b/sock
[info] started sbt server
sbt:project_sbt>
Install Scala 3 on KDE Neon|Kubuntu using SDKMAN
SDKMAN is a tool for managing similar versions of multiple software development kits.
Us the following commands to install scala on your system.
$ curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
Check the SDK version using the following command.
sdk version
Sample Output
==== BROADCAST =================================================================
* 2022-03-19: schemacrawler 16.16.12 available on SDKMAN! https://www.schemacrawler.com/changes-report.html
* 2022-03-19: jbang 0.92.1 available on SDKMAN! https://github.com/jbangdev/jbang/releases/tag/v0.92.1
* 2022-03-18: jbang 0.92.0 available on SDKMAN! https://github.com/jbangdev/jbang/releases/tag/v0.92.0
================================================================================
SDKMAN 5.14.1
Install scala using the following command.
sdk install scala
Sample Output
Installing: scala 3.1.1
Done installing!
Setting scala 3.1.1 as default.
Check the scala version
scala -version
Sample Output
Scala code runner version 3.1.1 -- Copyright 2002-2022, LAMP/EPFL
4. Manual Installation of Scala 3 on KDE Neon|Kubuntu
You can download the archive file for the latest releases of Scala 3 from the Scala Download Official page. Alternatively, you can pull the latest release from Github.
Install curl first if you do not have it.
sudo apt install curl -y
Pull the file using curl
LATEST_VER=$(curl -s https://api.github.com/repos/lampepfl/dotty/releases/latest|grep tag_name | cut -d '"' -f 4)
wget https://github.com/lampepfl/dotty/releases/download/$LATEST_VER/scala3-$LATEST_VER.tar.gz -O Scala-${LATEST_VER}.tar.gz
Extract the file using the following command.
tar xvf Scala-${LATEST_VER}.tar.gz && rm -f Scala-${LATEST_VER}.tar.gz
Move the file to a set directory.
sudo mv scala3-*/ /usr/local/share/scala
Install java.
sudo apt-get install default-jdk -y
Set java and scala environment variables.
nano ~/.bashrc
Set as shown below
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export SCALA_HOME=/usr/local/share/scala
export PATH=$PATH:$SCALA_HOME/bin
Check the scala version
scala -version
Sample Output.
Scala code runner version 3.1.1 -- Copyright 2002-2022, LAMP/EPFL
Create Scala Project on KDE Neon|Kubuntu
Create a scala project
Create a project using the following command
nano hello.scala
Then append the code
object Hello {
def main(args: Array[String]) = {
println("Hello from Technixleo!")
}
}
Save the file and exit the editor using CTRL + X
and type y
then press Enter
Then run the code.
scala hello.scala
Sample Output
Hello from Technixleo!
Create a Scala Project with sbt
Download a hello world template from GitHub
sbt new scala/hello-world.g8
Enter the name you would prefer.
A template to demonstrate a minimal Scala application
name [Hello World template]: HelloWorld
Initialize sbt
cd helloworld
Modify the code
nano src/main/scala/Main.scala
Sample output
object Main extends App {
println("Hello from Tecnixleo.com!")
}
Save and exit the file.
Initialize the sbt server
sbt
Then run the file
run
Sample output.
[info] Compilation completed in 12.249s.
[info] running Main
Hello from Tecnixleo.com!
[success] Total time: 16 s, completed Mar 20, 2022, 7:49:25 PM
sbt:hello-world>
Conclusion
From this guide, You learned how to install Scala 3 on Kubuntu|KDE Neon system using the available options like coursier, sbt, SDKMAN, and Manually. You also learned how to create a scala project and run the program also suing sbt.
Similar guides:
- Install and Configure PostgreSQL on Kubuntu | KDE Neon
- How To Install OpenOffice on KDE Neon / Kubuntu
- Install and Use Dropbox Client on KDE Neon|Kubuntu