The instructions below cover both Scala 2 and Scala 3.
Try Scala without installing anything
To start experimenting with Scala right away, use “Scastie” in your browser. Scastie is an online “playground” where you can experiment with Scala examples to see how things work, with access to all Scala compilers and published libraries.
Scastie supports both Scala 2 and Scala 3, but it defaults to Scala 3. If you are looking for a Scala 2 snippet to play with, click here.
Install Scala on your computer
Installing Scala means installing various command-line tools such as the Scala compiler and build tools. We recommend using the Scala installer tool “Coursier” that automatically installs all the requirements, but you can still manually install each tool.
Using the Scala Installer (recommended way)
The Scala installer is a tool named Coursier, whose main command is named
It ensures that a JVM and standard Scala tools are installed on your system.
Install it on your system with the following instructions.
Follow the instructions to install the
cs launcher then run:
$ ./cs setup
Along with managing JVMs,
cs setup also installs useful command-line tools:
- A JDK (if you don’t have one already)
- The sbt build tool
- Ammonite, an enhanced REPL
- scalafmt, the Scala code formatter
scalac(the Scala 2 compiler)
scala(the Scala 2 REPL and script runner).
For more information about
cs setupinstalls the Scala 2 compiler and runner (the
scalacommands, respectively). This is usually not an issue because most projects use a build tool that works with both Scala 2 and Scala 3. Nevertheless, you can install the Scala 3 compiler and runner as command-line tools by running the following additional commands:
$ cs install scala3-compiler $ cs install scala3
You only need two tools to compile, run, test, and package a Scala project: Java 8 or 11, and sbt. To install them manually:
- if you don’t have Java 8 or 11 installed, download Java from Oracle Java 8, Oracle Java 11, or AdoptOpenJDK 8/11. Refer to JDK Compatibility for Scala/Java compatibility detail.
- Install sbt
Create a “Hello World” project with sbt
Once you have installed sbt, you are ready to create a Scala project, which is explained in the following sections.
To create a project, you can either use the command line or an IDE. If you are familiar with the command line, we recommend that approach.
Using the command line
sbt is a build tool for Scala. sbt compiles, runs, and tests your Scala code. (It can also publish libraries and do many other tasks.)
To create a new Scala project with sbt:
cdto an empty folder.
- Run the command
sbt new scala/scala3.g8to create a Scala 3 project, or
sbt new scala/hello-world.g8to create a Scala 2 project. This pulls a project template from GitHub. It will also create a
targetfolder, which you can ignore.
- When prompted, name the application
hello-world. This will create a project called “hello-world”.
- Let’s take a look at what just got generated:
- hello-world - project (sbt uses this for its own files) - build.properties - build.sbt (sbt's build definition file) - src - main - scala (all of your Scala code goes here) - Main.scala (Entry point of program) <-- this is all we need for now
With an IDE
You can skip the rest of this page and go directly to Building a Scala Project with IntelliJ and sbt
Open hello-world project
Let’s use an IDE to open the project. The most popular ones are IntelliJ and VSCode. They both offer rich IDE features, but you can still use many other editors.
- Download and install IntelliJ Community Edition
- Install the Scala plugin by following the instructions on how to install IntelliJ plugins
- Open the
build.sbtfile then choose Open as a project
Using VSCode with metals
- Download VSCode
- Install the Metals extension from the Marketplace
- Next, open the directory containing a
build.sbtfile (this should be the directory
hello-worldif you followed the previous instructions). When prompted to do so, select Import build.
Under the hood, Metals communicates with the build tool by using the Build Server Protocol (BSP). For details on how Metals works, see, “Write Scala in VS Code, Vim, Emacs, Atom and Sublime Text with Metals”.
Play with the source code
View these two files in your IDE:
When you run your project in the next step, the configuration in build.sbt will be used to run the code in src/main/scala/Main.scala.
Run Hello World
If you’re comfortable using your IDE, you can run the code in Main.scala from your IDE.
Otherwise, you can run the application from a terminal with these steps:
sbt. This opens up the sbt console.
~is optional and causes sbt to re-run on every file save, allowing for a fast edit/run/debug cycle. sbt will also generate a
targetdirectory which you can ignore.
When you’re finished experimenting with this project, press
[Enter] to interrupt the
exit or press
[Ctrl+D] to exit sbt and return to your command line prompt.
Once you’ve finished the above tutorials, consider checking out:
- The Scala Book (see the Scala 2 version here), which provides a set of short lessons introducing Scala’s main features.
- The Tour of Scala for bite-sized introductions to Scala’s features.
- Learning Resources, which includes online interactive tutorials and courses.
- Our list of some popular Scala books.
- The migration guide helps you to migrate your existing Scala 2 code base to Scala 3.
There are a multitude of mailing lists and real-time chat rooms in case you want to quickly connect with other Scala users. Check out our community page for a list of these resources, and for where to reach out for help.