Setting up a Scala environment on Arch Linux

So you want to get hacking in Scala, but you don’t know where to start? Read on. This post is a summary of the bare minimum you need to get running.


First, become root, and install the Scala compiler package with

pacman -S scala

Now you can compile scala files with scalac, and run the REPL with scala.

This step might not be strictly necessary because sbt (below) downloads and uses the correct compiler version for you, but if you ever use scala without sbt, you’ll probably want this package.

sbt: the Simple1 Build Tool

Install the package with

pacman -S sbt

And you’re done!

Actually, you really should read the Getting Started guide, because otherwise, if you’re like me, you’re going to be completely baffled when you try to use it.

Basically, sbt is a build tool on steroids: if it has no configuration file (a “.sbt build definition”), it will hunt down your project files using a bunch of rules. From the guide:

sbt will find the following automatically:

  • Sources in the base directory
  • Sources in src/main/scala or src/main/java
  • Tests in src/test/scala or src/test/java
  • Data files in src/main/resources or src/test/resources
  • jars in lib

Once loaded (which takes a long time the first time around2), you’ll be in the sbt console. Some useful commands to note:

  • run: Run your program
  • console: Get a scala REPL. Ctrl+D to quit back to sbt.
  • clean: Clean all built files
  • compile: Go on, take a wild guess.

Also useful: you can make a command run in the background whenever you change a file by prefixing it with ~. For example, > ~ compile will recompile your project on every source file change.

See the guide for more commands.

  1. It could be simpler. Just sayin’.↩︎

  2. It takes so long because it’s pulling down dependencies for your package. Dependencies even include the version of the scala compiler your program uses, but don’t worry, these are cached in $HOME/.ivy2/, so everything should be less painful after the first time.↩︎