Install Scala on FreeBSD
FreeBSD installs the JDK from its package collection. scala-cli is a JVM application, and its releases include a launcher jar, which is the form that needs nothing from the system beyond the JDK the page installs first. This is the FreeBSD page of the install overview; the commands were not run here, because they install on FreeBSD and need the network.
The JDK
The package collection carries a port of OpenJDK for each supported release, and the JDK one — not the JRE — brings javac:
sudo pkg install openjdk21
not run in this environment
pkg install writes the files under /usr/local and the Java launcher is on the PATH after the install. javac -version proves that the compiler came with it.
scala-cli
The release page of scala-cli publishes a native launcher for Linux, macOS and Windows, and a JVM launcher jar. On FreeBSD the jar is the portable choice: it is the same code, run by the JDK the page just installed.
mkdir -p ~/bin
fetch -o ~/bin/scala-cli.jar https://github.com/VirtusLab/scala-cli/releases/latest/download/scala-cli.jar
not run in this environment
An alias keeps the command the course writes:
alias scala-cli='java -jar ~/bin/scala-cli.jar'
not run in this environment
The alias belongs in ~/.shrc for sh or in the profile of the shell in use. The native Linux launcher also runs through FreeBSD's Linux compatibility layer, but that layer is a Linux system setting rather than a language install, so this page stays with the jar.
Check the version
java -version
java -jar ~/bin/scala-cli.jar version
not run in this environment
java -jar ... version is the same command the alias runs, so a failure here is the answer before the alias is written. A Could not find or load main class after a fetch means the jar was saved as an error page: the release URL redirects, and fetch follows it.
Related
- Scala in Docker: the next page of the install overview.
- Install Scala on macOS: Homebrew and the same jar on another system.
- Install Scala and check the version: the overview and the version lines.
- Java: the JDK this page installs.
Article author: Arthur Isaev