Install Scala on Ubuntu

Ubuntu installs the JDK from its own repository and scala-cli with the installer script, because the distribution's own Scala package is Scala 2 and this course is Scala 3. This is the Ubuntu page of the install overview; the commands are shown and not run here, because they install on Ubuntu and need the network.

The JDK

One package brings the compiler and the virtual machine, and default-jdk points at the release the distribution supports:

sudo apt update
sudo apt install -y default-jdk curl

not run in this environment

-y answers the confirmation prompt. A JDK from a newer release than the distribution's is a matter of the openjdk-21-jdk package, and the version the course uses is 21.

scala-cli

The installer downloads the launcher and writes it under the home folder:

curl -sSLf https://scala-cli.virtuslab.org/get | sh

not run in this environment

The script detects the architecture and installs into ~/.local/share/scala-cli or a folder it prints; in most shells it also appends the folder to the PATH line of the profile. A shell opened before the install does not see the change, so open a new one.

Check the version

java -version
scala-cli version

not run in this environment

A scala-cli: command not found right after the install means the folder is not on this shell's PATH; a JAVA_HOME is not set from the launcher means the JDK package did not arrive. Both are install problems, not language problems.

Related

Автор статьи: Arthur Isaev