Getting Started

Language

Try Scala without installing anything

You can try Scala in your browser, with access to all Scala compilers and all published libraries.

Install Scala

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.

The Scala installer is a tool named cs that ensures that a JVM and standard Scala tools are installed on your system.

  • Download the cs tool and execute the setup command

Follow the instructions to install the cs launcher then run:

$ ./cs setup

Along with managing JVMs, it also installs useful command line tools: Ammonite, coursier, scala (the Scala REPL and script runner), scalac (the Scala compiler), sbt, and scalafmt.

For more information, read coursier-cli documentation.

…Or manually

  1. 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.
  2. 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 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.)

  1. cd to an empty folder.
  2. Run the following command sbt new scala/hello-world.g8. This pulls the ‘hello-world’ template from GitHub. It will also create a target folder, which you can ignore.
  3. When prompted, name the application hello-world. This will create a project called “hello-world”.
  4. 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

More documentation about sbt can be found in the Scala Book and in the official sbt documentation

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.

Using IntelliJ

  1. Download and install IntelliJ Community Edition
  2. Install the Scala plugin by following the instructions on how to install IntelliJ plugins
  3. Open the build.sbt file then choose Open as a project

Using VSCode with metals

  1. Download VSCode
  2. Install the Metals extension from the Marketplace
  3. Next, open the directory containing a build.sbt file. When prompted to do so, select Import build.

Run Hello World

Open a terminal

  1. cd into hello-world.
  2. Run sbt. This will open up the sbt console.
  3. Type ~run. The ~ 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 target directory which you can ignore.

Next Steps

Once you’ve finished the above tutorials, consider checking out:

Getting Help

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.

Contributors to this page: