Install Scala on macOS
macOS has no JDK of its own, so Homebrew installs one and scala-cli either comes from Homebrew or from its installer. This is the macOS page of the install overview; the commands were not run here, because they install on macOS with Homebrew, and macOS asks for the Xcode command line tools before Homebrew itself runs.
The JDK
brew install openjdk@21
not run in this environment
Homebrew installs the JDK into its own prefix and does not link it into the system Java location, because macOS already has a stub there; the Java JDK of this course is the same openjdk@21 formula. The formula prints the two lines that fix it: a symbolic link into /Library/Java/JavaVirtualMachines, and a JAVA_HOME export in the shell profile. The link is what makes /usr/libexec/java_home find the release.
scala-cli
Either package manager works. Homebrew keeps the launcher with the rest of the packages, and the installer script puts a single binary in the home folder:
brew install scala-cli
not run in this environment
curl -sSLf https://scala-cli.virtuslab.org/get | sh
not run in this environment
Choose one: two launchers on the PATH mean that which scala-cli decides which one runs, and a version that does not match the one a colleague sees is a confusing hour. A project pins its own Scala version in project.scala anyway, which is what the scala-cli lesson shows.
Check the version
java -version
scala-cli version
not run in this environment
On Apple silicon the JDK is an ARM build and the launcher is an ARM binary; a Bad CPU type in executable means an Intel build was installed under Rosetta. The version lines are the same three facts as on every other system: the JVM, the Scala version and the vendor.
Related
- Install Scala on FreeBSD: the next system page.
- Install Scala on Windows 11: the installer script.
- scala-cli, directives and scripts: the version a project pins.
- Scala in Docker: a toolchain without Homebrew.
Автор статьи: Arthur Isaev