Scala 3 Odyssey: Part 2 — Install and Setup the Scala Toolkit

Antonel Ernest Pazargic
8 min readJun 11, 2024

--

Generated by OpenAI DALL-E

The time has come to unveil my next article in this series.
If you missed the previous one, an intro about scala programming language, you can find at

Scala toolkit installation

For the installation I am going to consider only macOS, the OS I use on daily basis.

To start programming in scala is necessary to install the following:

Mandatory

  • Java (a LTS version is recommended: versions 17 or 21),
  • Scala (a LTS version is recommended: 3.4.2 at the time of writing)

Optional, but highly recommended

  • Build tool:
    In the articles I am going to use only SBT, but if someone is more acquainted with mill, maven or gradle, there is quite fine to use any of them as well,
  • scala-cli,
  • ammonite

Installation Steps

  • First we must install homebrew on macOS.

Homebrew is a package manager for macOS, and it is the recommended way of installing software on macOS.
I regularly use it to install different software like neovim, sdkman, etc.
Installing homebrew is easy, just run the following command in the terminal:

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  • Next, the recommended way of installing anything JVM based is by the usage of the sdkman tool.

Sdkman is a command line tool that simplifies the process of installing, updating, and configuring development environments for Java, Groovy, Scala, Kotlin, Ceylon, and many others.

To install it on macOS issue the command

curl -s “https://get.sdkman.io" | bash

To get a list of all available versions for a sdk run the following command

sdk list $sdk

for instance to see all available java version we might use the following command

sdk list java

For instance we might install java using the following sdkman command.

sdk install java 11.0.11.hs-adpt

  • Install java 21 using

sdk install java 21.0.3-oracle

and check the installation by running scala — version

  • Install scala

sdk install scala 3.4.2

and run

scala — version

to verify the installation/setup.

To install a newer version first find out the available versions using

sdk list scala

Now, that we have the installation of the scala toolkit out of the way, let’s talk a bit about each of the tools.

Considering this series is not about homebrew, sdkman or java, and scala was described in the previous article, I am going to focus on the other tools.

SBT (Simple Build Tool)

SBT is a build tool for scala and java projects, but mostly used for scala projects.
Its intention is to make simple things simple and complex things possible.
To install it on macOS, as you might guess, you can use homebrew, by running the following command

brew install sbt

to install the latest version, or brew install sbt 1.10.0 to install a specific version.

But, having at our disposal the sdkman tool, the more straightforward way to install SBT is by using this tool via the following command

sdk install sbt

or

sdk install sbt 1.10.0

to install a specific version.

Popular editors like VS Code, or IDEs like IntelliJ Idea have plugins that support SBT and make the development process quite a pleasure.

If it would be to mention some of the main features of SBT, I would enlist the following:

  • incremental compilation,
  • dependency management,
  • testing,
  • packaging,
  • deployment,
  • extensibility via plugins,
  • flexibility,
  • integration with different IDEs,
  • project generation via giter8.

I admit that I was (and still I am) a bit scared about the complexity of SBT at the first glance, but I am confident that learning scala will also help understanding the SBT DSL better.
I expect to dive deeper into SBT in one of the next articles in this series, but for the impatient ones here is how you can generate a working simple (hello world) scala project using it.

First create a new project

sbt new scala/scala3.g8

And then run the project

sbt run

Scala-cli

It is time to talk about one of my favorite tools for scala development, scala-cli.
It assists in creating, building, running, and testing scala files or projects.

Some of the main features of the scala-cli are:

  • create a new scala project,
  • build the project,
  • run a sc or scala file,
  • run a scala project,
  • install a particular scala version using directives like

//> using test.dep org.scalatest::scalatest:3.2.18

  • package the project as a fatjar or a native image, amongst other variants.

More about scala-cli and testing some of its main features can be discovered at

and in some of my next articles.

Notes:

  • Scala CLI will be builtin in scala 3.5+

Coursier

An easier way of installing the scala toolchain is through the Coursier installation and setup.
Using our old best friend homebrew, coursier can be install by running

brew install coursier/formulas/coursier

and, then, setup using

cs setup

Coursier bundles the following tools/SDKs:

  • cs (coursier itself)
  • scala/scalac
  • scala-cli
  • sbt
  • ammonite
  • scalafmt — scala code formatter
Coursier installation

Notes:

  • Coursier setup figured out the tools (SDK) that are already installed through other means,
  • It is mandatory for the neovim vim-metals (LSP plugin for scala development), in case your favorite editor is neovim.

More about coursier at

Some Other Essential Tools for Scala Development

  • Visual Studio Code

There is no doubt that Visual Studio Code became for quite some years now my favorite editor for many software activities, and for good reasons.
It is fast, highly customizable, and extendable via plugins.
Moreover, for scala development, it has a very good extension (Metals extension) that makes the development process an real pleasure.

Some of the main features of Metals are:

  • code completion,
  • code navigation,
  • find references,
  • refactoring,
  • run/debug applications, scripts, tests,
  • extensions for different languages via LSP,
  • good integration with Copilot (AI pair programming tool).

A sneak peak of the Metals extension in action is presented below.

VS Code and Metals (Scala development)
  • NeoVim (lazy.vim)

What to say about NeoVim, the new vim on steroids?
It is performant, highly customizable and extendable via plugins, much like VS Code.
I do consider there is quite a steep curve to learn it, but the time invested in learning it is worth it.
In my personal opinion learning vim is a must for any software developer, and the sooner the better.
It helps me to be more productive and precise at editing code or documents, regardless the editor/IDE I use (VS code, neovim, IntelliJ Idea).
NeoVim is based on vim text editor, and lua programming language used embedded for customizing and extending neovim.
To install NeoVim with homebrew just run

brew install neovim

I am still unsure if I’ve approached learning vim the right way by installing and using the neovim distribution lazy.vim. Time will tell, but so far I am quite happy with it, considering NeoVim (vim) is a very hard to crack nut.

NeoVim with vim-metals plugin installed, for scala development
vim-metals plugin shown in the lazy.vim plugins management
  • Jetbrains IntelliJ Idea (Community or Ultimate Editions)

Needless to say that IntelliJ Idea is one of the best IDEs for software development, and it is the preferred tool to develop software in Java, Scala, Kotlin, Python for many software developers around the world.
Scala development is offered in both Community and Ultimate Editions via Scala plugin, which is bundled.
My preferred way of installing IntelliJ Idea is through Jetbrains Toolbox.

Jetbrains Toolbox for the management of Jetbrains Tools such as IntelliJ Idea
How a scala projects looks like in IntelliJ Idea, thanks to the features offered by the Scala plugin

Online playgrounds

For the impatient or for the ones that are not willing, or have the time, to install the scala toolkit, there are some online playgrounds that can be used to experiment with scala.
My favorite, that I’ve used quite frequently is scastie

It works pretty well and allows adding (using) external libraries via Build Settings.

Ammonite

Enlisting all the above amazing tools helping with scala development won’t be completed without mentioning ammonite.
Ammonite is a modern and powerful Scala REPL.
I admit that I use it quite rarely considering I use mostly VS Code & metals for scala development.
But, nonetheless, it is a powerful tool and it worth mentioning.
To install ammonite using coursier, run the following command

cs install ammonite

if it is not already installed via cs setup.

And to start the ammonite REPL just run the following

cs launch ammonite

References

  • A summary of all my articles in this mini-series
  • Homebrew
  • Sdkman
  • Scala
  • Metals
  • Ammonite
  • Scala-cli
  • VS Code
  • NeoVim
  • IntelliJ Idea
  • Coursier
  • Lazy.vim
  • scala-cli in scala 3.5+

Closing notes

In this article I’ve presented the necessary steps to install the scala toolkit on macOS.
I’ve also described some of the most useful tools for scala development.

Please feel free to share you thoughts, comments, or suggestions.
If you like this article please clap it, and share it with your friends and colleagues.

Thank you for reading! Stay tuned for more.

--

--