Try Scala without installing anything
You can try Scala in your browser, with access to all Scala compilers and all published libraries.
Installing Scala means installing various command-line tools such as the Scala compiler and build tools. We recommend using the Scala installer tool 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
cs that ensures that a JVM and standard Scala tools are installed on your system.
- Download the
cstool and execute the
Follow the instructions to install the
cs launcher then run:
$ ./cs setup
For more information, read coursier-cli documentation.
- 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
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.
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.)
cdto an empty folder.
- Run the following command
sbt new scala/hello-world.g8. This pulls the ‘hello-world’ 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. When prompted to do so, select Import build.
Run Hello World
Open a terminal
sbt. This will open 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.
Once you’ve finished the above tutorials, consider checking out:
- The Scala Book, 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.
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.