Install Scala on Windows 11

Windows 11 installs a JDK and scala-cli in two steps. The JDK comes from a package manager or the Temurin installer, and scala-cli from its installer script; both put a command on the PATH. This is the Windows page of the install overview, and none of its commands run here, because Windows 11 is the system they install on: the page shows what a reader types and marks the output as not run.

The JDK

winget is part of Windows 11 and installs the Temurin build of OpenJDK 21, which is the release this course and its Java pages use:

winget install --id EclipseAdoptium.Temurin.21.JDK

not run in this environment

The installer writes JAVA_HOME and adds %JAVA_HOME%\bin to the user PATH. A new terminal is needed for the change; in the current PowerShell, $env:Path shows what the shell has.

scala-cli

The installer is a PowerShell script that downloads the launcher and puts it in the user profile:

Invoke-WebRequest -Uri https://scala-cli.virtuslab.org/get -OutFile scala-cli.ps1
powershell -ExecutionPolicy Bypass -File scala-cli.ps1

not run in this environment

ExecutionPolicy Bypass is needed because a downloaded script is not signed by a publisher Windows trusts; it applies to that one run. The script asks where to install, and the default is a folder under the user profile that it adds to PATH.

Check the version

Two commands prove the install: the JDK answers, and scala-cli finds it.

java -version
scala-cli version

not run in this environment

The first line of java -version is the version and the build; the two lines of scala-cli version are the launcher and the Scala version it would compile with by default. A 'scala-cli' is not recognized means the folder is not on the PATH of this shell: open a new terminal, or add the folder by hand.

Related

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