Skip to content

Instantly share code, notes, and snippets.

@fscm
Created February 1, 2022 18:31
Show Gist options
  • Save fscm/04bf1b1f567d7e5b3af5ecf2a2fd727b to your computer and use it in GitHub Desktop.
Save fscm/04bf1b1f567d7e5b3af5ecf2a2fd727b to your computer and use it in GitHub Desktop.
[macOS] Install Scala programming language

[macOS] Install Scala programming language

Instructions on how to install the Scala programming language on macOS.

Uninstall

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}

Prerequisites

Java Development Kit

Java Development Kit needs to be installed on your local computer. Instructions on how to install Java on macOS can be found here.

Install

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

Configure

Add the following lines to the .bash_profile file:

# scala home
export SCALA_HOME="/Library/Frameworks/Scala.framework/Versions/Current"

Verify

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

Test

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment