Instructions on how to install the Scala programming language on macOS.
First step should be to unsinstall any previous Scala installation. This step can be skipped if no Scala programming language was previously installed.
This will completelly remove any Scala programming language version previously installed. If you which to keep any existing Scala versions installed you should skip this step.
To uninstall any previous Scala installations use the following commands:
sudo rm -rf "/Library/Frameworks/Scala.framework"
sudo rm -rf "/private/etc/paths.d/Scala"
(This is your Scala REPL history, don't delete this if you plan on re-installing Scala)
rm -f ~/.dotty_history}
Java Development Kit needs to be installed on your local computer. Instructions on how to install Java on macOS can be found here.
The Scala programming language can be obtained here. Copy the version number that you want to install from there.
To install the Scala programming language use the following commands:
SCALA_VERSION=3.1.1
sudo install -d "/Library/Frameworks/Scala.framework/Versions/${SCALA_VERSION}"
sudo ln -s -f "/Library/Frameworks/Scala.framework/Versions/${SCALA_VERSION}" "/Library/Frameworks/Scala.framework/Versions/Current"
curl --silent --location --retry 3 "https://github.com/lampepfl/dotty/releases/download/${SCALA_VERSION}/scala3-${SCALA_VERSION}.tar.gz" \
| sudo tar xz --no-same-owner --strip-components=1 --exclude=*.bat -C "/Library/Frameworks/Scala.framework/Versions/${SCALA_VERSION}"
echo '/Library/Frameworks/Scala.framework/Versions/Current/bin' | sudo tee /private/etc/paths.d/Scala
Add the following lines to the .bash_profile
file:
# scala home
export SCALA_HOME="/Library/Frameworks/Scala.framework/Versions/Current"
Open a new terminal window and check if the CMake tool is installed:
scala --version
scalac --version
Also check if the SCALA_HOME environment variable was defined using the following command:
echo $SCALA_HOME
To test the installed tools create a file called Test.scala
with the
following text:
object Test {
def main(args: Array[String]): Unit = {
println(s"${2 + 2}")
}
}
Then run the following command:
scala Test.scala