TExcelTAD
Home › Scala › Scala Get Started

Scala Get Started

To run Scala on your own computer you need two things: a JDK (Java Development Kit, version 17 or newer is a good choice) and a Scala tool. In 2026 the easiest tool is scala-cli, which is now the official scala command. For larger projects with many modules, most teams use sbt, the Scala build tool.

Installing

The recommended installer is Coursier (cs), which installs a JDK, scala, scalac and sbt in one go.

System Command
macOS (Homebrew) brew install coursier && coursier setup
Linux download cs from get-coursier.io, then ./cs setup
Windows run the cs-x86_64-pc-win32.zip installer, then cs setup

After the setup finishes, open a new terminal and check the versions:

bash · try it yourself
scala --version
Scala code runner version: 1.8.4
Scala version (default): 3.7.1

Your first file with scala-cli

Create a file called hello.scala:

scala
@main def hello(): Unit =
  println("Hello from my own machine!")

Then run it. The first run downloads the compiler, so it takes a little while; later runs are fast.

bash · try it yourself
scala run hello.scala
Compiling project (Scala 3.7.1, JVM (17))
Compiled project (Scala 3.7.1, JVM (17))
Hello from my own machine!

scala-cli can also start an interactive REPL (Read–Eval–Print Loop) where you type expressions and see their values immediately:

bash · try it yourself
scala
Welcome to Scala 3.7.1 (17.0.12, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> 

Inside the REPL, 1 + 2 prints val res0: Int = 3. Type :quit to leave.

Two kinds of entry points

Both of these styles work; this course uses them interchangeably.

scala · try it yourself
@main def run(): Unit =
  println("Started with @main")
Started with @main
scala · try it yourself
object Main:
  def main(args: Array[String]): Unit =
    println("Started with an object and a main method")
    println(s"Number of arguments: ${args.length}")
Started with an object and a main method
Number of arguments: 0

The object Main style is the one you will meet in older code and in Java-style projects. @main is shorter and can even take typed parameters, which scala-cli fills from the command line.

Directives: dependencies in the file

scala-cli reads special //> using comments at the top of a file. They set the Scala version or pull in libraries without a separate build file:

scala
//> using scala 3.7.1
//> using dep com.lihaoyi::os-lib:0.11.4

@main def listFiles(): Unit =
  os.list(os.pwd).foreach(println)

Projects with sbt

When your code grows into many files, tests and sub-projects, use sbt. A minimal project looks like this:

text
my-app/
  build.sbt
  project/build.properties
  src/main/scala/Main.scala
  src/test/scala/MainSuite.scala
scala
// build.sbt
ThisBuild / scalaVersion := "3.7.1"

lazy val root = project
  .in(file("."))
  .settings(name := "my-app")
bash · try it yourself
sbt run
[info] welcome to sbt 1.11.2 (Eclipse Adoptium Java 17.0.12)
[info] loading project definition from /home/me/my-app/project
[info] set current project to my-app (in build file:/home/me/my-app/)
[info] running hello
Hello from my own machine!
[success] Total time: 2 s
Task scala-cli sbt
Run a program scala run . sbt run
Compile scala compile . sbt compile
Run tests scala test . sbt test
Start a REPL scala sbt console
Best for scripts, small apps, learning multi-module projects

Tip: Start every new experiment with scala-cli and a single file. Move to sbt (or Mill) only when you actually need what a full build tool offers.

Editors

Good editor support comes from Metals, a language server that works with VS Code, Neovim and others. IntelliJ IDEA with the Scala plugin is the other popular choice. Both give you auto-completion, inferred-type hints and inline errors.

Test yourself

Which command runs a single Scala file with scala-cli?

  1. scalac hello.scala
  2. scala run hello.scala
  3. sbt hello.scala
  4. java hello.scala

What is the purpose of a //> using dep ... line?

  1. It is an ordinary comment with no effect
  2. It tells scala-cli to download and add a library
  3. It imports a Java package
  4. It sets a compiler warning

In an sbt project, where does the main source code live by convention?

  1. src/main/scala
  2. lib/
  3. scala/src
  4. Next to build.sbt only