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.
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
cs
tool and execute thesetup
command
$ brew install coursier/formulas/coursier && cs setup
Alternatively, if you don’t use Homebrew
$ curl -Lo cs https://git.io/coursier-cli-macos && chmod +x cs && (xattr -d com.apple.quarantine cs || true) && ./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 #
- 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.
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.)
cd
to 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 atarget
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
- 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 #
- 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 VSCode with metals #
- Download VSCode
- Install the Metals extension from the Marketplace
- Next, open the directory containing a
build.sbt
file. When prompted to do so, select Import build.
Run Hello World #
Open a terminal
cd
intohello-world
.- Run
sbt
. This will open up the sbt console. - 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 atarget
directory which you can ignore.
Next Steps #
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.
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.