Scala Setup & Installation

Before you write your first Scala program, you need three things on your computer: Java (because Scala runs on the JVM), the Scala compiler, and a build tool. This guide walks you through each step clearly. The whole process takes about 10–15 minutes.

What You Need

Think of the setup like equipping a kitchen. Java is the stove (the engine that runs everything). Scala is the recipe book (the language). SBT or Coursier is the grocery delivery service (it fetches libraries and manages your project). The IDE or text editor is your work surface.


Your Computer
│
├── Java (JVM) ──────── powers everything
│
├── Scala Compiler ──── translates Scala to JVM bytecode
│
├── SBT / Coursier ──── manages projects and dependencies
│
└── IDE (IntelliJ / VS Code) ── where you write code

Step 1: Install Java

Scala requires Java 8 or higher. Java 11 and Java 17 are the most common choices for Scala projects. Download the JDK (Java Development Kit) from Adoptium (formerly AdoptOpenJDK) at adoptium.net. Choose the installer for your operating system — Windows, macOS, or Linux.

After installation, open your terminal or command prompt and verify Java works:

java -version

You should see output like:

openjdk version "17.0.9" 2023-10-17

If you see an error, the JDK installation did not complete correctly. Re-run the installer and make sure you check the option to add Java to your system PATH.

Step 2: Install Scala with Coursier (Recommended)

Coursier is the official Scala installer. It downloads Scala, SBT, and related tools with a single command. It is the fastest way to get a working Scala environment.

On macOS or Linux:

curl -fL https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz | gzip -d > cs
chmod +x cs
./cs setup

On Windows:

Download the cs-x86_64-pc-win32.zip from the Coursier releases page on GitHub. Extract it, then run cs.exe setup in your command prompt.

The cs setup command installs Scala, SBT, the Scala REPL, and other tools automatically. It also updates your PATH variable so you can run these tools from any folder.

After setup, restart your terminal and verify:

scala -version

Expected output:

Scala code runner version 3.x.x

Step 3: Install SBT (Build Tool)

SBT stands for Simple Build Tool (though experienced Scala developers sometimes joke it is not always simple). SBT manages your project structure, downloads dependencies, compiles code, and runs tests. Coursier installs SBT automatically in Step 2. To check:

sbt -version

If SBT is missing, install it directly from scala-sbt.org.

Step 4: Choose an Editor or IDE

Two editors dominate Scala development:

IntelliJ IDEA with Scala Plugin

IntelliJ IDEA is the most feature-rich option. The free Community Edition works well for Scala. After installing IntelliJ, go to Plugins → search for Scala → click Install. IntelliJ gives you code completion, refactoring tools, inline error messages, and an integrated debugger.

VS Code with Metals

VS Code is lighter and faster to start. Install the Metals extension from the VS Code marketplace. Metals is the Scala language server — it provides smart code completion, go-to-definition, and error highlighting inside VS Code. Metals automatically imports SBT projects and manages compilation in the background.


IntelliJ IDEA                VS Code + Metals
──────────────               ────────────────
Full IDE features            Lightweight editor
Better refactoring           Fast startup
Heavier on RAM               Lower memory use
Best for large projects      Best for quick editing

Step 5: Verify Everything Works

Open your terminal and type:

scala

This opens the Scala REPL (Read-Eval-Print Loop) — an interactive console where you can type Scala code and see results immediately. Type this and press Enter:

println("Hello, Scala!")

You should see:

Hello, Scala!

Type :quit or press Ctrl+D to exit the REPL.

Create Your First SBT Project

SBT provides a project template command. In your terminal:

sbt new scala/scala3.g8

SBT asks for a project name. Type something like my-first-scala and press Enter. SBT creates a folder with this structure:

my-first-scala/
├── build.sbt          ← project configuration
├── project/
│   └── build.properties
└── src/
    └── main/
        └── scala/
            └── Main.scala   ← your code goes here

Open the project in your IDE. The build.sbt file tells SBT which version of Scala to use and which libraries to include. The src/main/scala/ folder is where all your Scala source files live.

Common Setup Problems

Java Not Found

The terminal says java: command not found. This means Java is installed but not added to the system PATH. On Windows, search for "Environment Variables" in the Start menu and add the Java bin folder to the PATH variable. On macOS and Linux, add export PATH=$PATH:/path/to/java/bin to your .bashrc or .zshrc file.

Scala REPL Hangs on First Start

Coursier sometimes downloads additional components the first time you run Scala. Wait a minute for the download to complete. A stable internet connection speeds this up.

SBT Takes Too Long to Load

SBT downloads project dependencies on first run. This is normal. Once downloaded, subsequent runs are much faster because SBT caches everything locally in your home folder under .ivy2 and .sbt.

Recommended Setup Summary


[Java 17 JDK]
      ↓
[Coursier cs setup]  →  installs Scala 3 + SBT + tools
      ↓
[IntelliJ + Scala plugin]  OR  [VS Code + Metals]
      ↓
[sbt new scala/scala3.g8]  →  creates a working project
      ↓
[Ready to code!]

With this setup, you can write, compile, and run Scala programs. The next topic covers writing your very first Scala program from scratch.

Leave a Comment

Your email address will not be published. Required fields are marked *