Install Scala and check the version

A Scala toolchain is a JDK plus scala-cli. The JDK supplies the virtual machine and the class library, scala-cli resolves a Scala version, compiles the sources and runs them, and the compiler itself is scalac, which ships inside the same installation. This page gives the overview and links one page per system; each of those pages holds the commands of that system.

A JDK first

Scala 3 needs a JDK — the compiler is a JVM program — and this course uses Java 21, the long-term release that virtual threads arrived in. Install the JDK of your system first, then check that the command is there:

java -version

openjdk version "21.0.13.1" 2026-11-17
OpenJDK Runtime Environment (build 21.0.13.1+2-alpine-r0)
OpenJDK 64-Bit Server VM (build 21.0.13.1+2-alpine-r0, mixed mode, sharing)

The first line is the one to read: the version, then the build. A JRE is not enough, because scalac compiles and needs the tools of a JDK, and so does sbt. The Java pages of this site have the install commands for each system.

scala-cli

scala-cli is one command that downloads a compiler, compiles and runs a file, a folder or a project, and reads its configuration from comments at the top of the source. The installation is one script:

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

not run in this environment

The installer needs the network, so the line above is shown and not run here. A reader with a connection runs it once and has the command for good. A package manager works as well: brew install scala-cli on macOS, sdk install scala-cli with SDKMAN, or the archive from the releases page. The per-system pages below give the command of each one.

A normal Scala installation also offers a scala command. In recent distributions that command is scala-cli under another name, so scala run hello.scala and scala-cli run hello.scala are the same run. The installation used for this course does not carry that alias, so every command of the course names scala-cli. The alias is written once, here, and marked as not run:

scala run hello.scala

not run in this environment

One page per system

The commands differ, the result is the same: a scala-cli command on the PATH and a version line that names the Scala it will compile with. The pages cover Windows, Ubuntu, Rocky Linux, macOS, FreeBSD and Docker.

Read the version lines

Three commands answer three different questions. The first is the virtual machine the compiler will run on, the second is the Scala version scala-cli would use by default, and the third is the compiler on the PATH:

scala-cli version

Scala CLI version: 1.19.0
Scala version (default): 3.10.1

scalac -version

Scala compiler version 3.10.1 -- Copyright 2002-2026, LAMP/EPFL

A program can read the same facts, which is how a build checks its toolchain. The three values are the JVM version, the Scala library version and the vendor of the JDK:

versions.scala

@main def versions(): Unit = println(System.getProperty("java.version")) println(scala.util.Properties.versionNumberString) println(scala.util.Properties.javaVendor)

scala-cli run --server=false versions.scala

21.0.13.1
3.10.1
Alpine

The numbers of your installation will differ; the three lines will not. A scala-cli that prints a Scala version other than the one a project asks for is not a problem: a //> using scala directive in the source picks the version for that project, which the scala-cli lesson shows.

Related

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

Изображение баннера