Try Scala without installing anything
To start experimenting with Scala 3 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.
Install Scala on your computer
Installing Scala means installing various command-line tools 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 install scala3-repl
$ cs install scala3-compiler
Along with managing JVMs,
cs setup also installs useful command line tools:
- A JDK
- The sbt and mill build tools
- Ammonite, an enhanced REPL
- scalafmt, the Scala formatter
- The Coursier CLI, to install further Scala-based applications
scalaccommand-line tools for Scala 2.13 – not Scala 3).
For more information, read the coursier-cli documentation.
… or manually
You only need two tools to compile, run, test, and package a Scala project: Java 8 or 11, and sbt. To install these manually:
- 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
To create a project, you can either use a command-line tool 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 this command
sbt new scala/hello-world.g8. This pulls the ‘hello-world’ template from GitHub. It also creates a target folder, 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 src/main/scala/ (all of your Scala code goes here) Main.scala (entry point of program) build.sbt (sbt’s build definition file)
The scala file
src/main/scala is all we need for now.
Open the “Hello, world” project
Let’s use an IDE to open the project. The most popular ones are IntelliJ IDEA and VS Code. They both offer rich IDE features, but you can still use many other editors.
Using IntelliJ IDEA
- Download and install IntelliJ Community Edition
- Install the Scala plugin by following the instructions on how to install IntelliJ plugins
- Open the build.sbt file, then choose Open as a project
Using VS Code with Metals
- Download VS Code
- Install the Metals extension from the Marketplace
- Next, open the directory containing your build.sbt file. When prompted to do so, select Import build.
Metals is a “Scala language server” that provides support for writing Scala code in VS Code and other editors like Atom, Sublime Text, and more, using the Language Server Protocol. (For details on how Metals works, see, “Write Scala in VS Code, Vim, Emacs, Atom and Sublime Text with Metals”.)
View 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 the “Hello, world” project
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 also generates a
targetdirectory for its own use, 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.
Now that you’ve created a first “Hello, world” example with Scala 3, you’re ready for some next steps. Consider checking out:
- The Scala 3 Book, which provides a set of short lessons introducing Scala’s main features
- The migration guide helps you to migrate your existing Scala 2 code base to Scala 3.
When you want to connect with other Scala users, there are several mailing lists and real-time chat rooms available. Check out our Scala community page for a list of these resources, and for where to reach out for help.