How to install sbt on Ubuntu For Scala and Java projects

Looking to work with Scala or Java on Linux? If so, you'll want the Scala Build Tool up and running.

How to install sbt on Ubuntu For Scala and Java projects Looking to work with Scala or Java on Linux? If so, you'll want the Scala Build Tool up and running.

Scala is a general-purpose, object-oriented programming language that is influenced by Java. In fact, Scala projects can be coded in the same way as Java projects. As well, a number of Java libraries (as well as other, third-party libraries) can be used within Scala.

Since Scala is in high demand for data processing and distributed programming, it is a language you might want to have in your toolkit. 

But if your development platform is Linux, you won't be able to work with Scala out of the box. To remedy that, you need the help of a cross-platform build tool, like sbt. Sbt (Scala Build Tool) offers native support for compiling Scala code and integrates with Scala test frameworks. 

SEE: Telephone interview cheat sheet: Software developer (TechRepublic Premium)

I'm going to walk you through the process of installing the necessary components to start working with sbt. I'll demonstrate on Ubuntu 19.04, but the tools can be installed on other distributions.

What you need

To make this happen, you need a working instance of Ubuntu Desktop 19.04, and a user account with sudo access. With those bits at the ready, let's get to work.

Installing Java

The first thing to do is install Java. In order to do that, we'll install the default JDK package. First update and upgrade Ubuntu with the commands:

sudo apt-get update
sudo apt-get upgrade -y

When this process completes, if necessary reboot the machine.

Install the default JDK with the command:

sudo apt-get install default-jdk -y

Install Scala

Next we'll install Scala. To do this, download the necessary .deb file with the command:

wget www.scala-lang.org/files/archive/scala-2.13.0.deb

Note: Check the Scala archive page to make sure you're downloading the latest version of Scala. 

With the Scala .deb file downloaded, install it with the command:

sudo dpkg -i scala*.deb

When that installation finishes, type the command scala to enter the scala prompt (to be certain the installation was successful - Figure A).

sbtb.jpg

Figure A: The Scala installation was a rousing success.

Exit the scala prompt with the command :quit.

Install SBT

Now it's time to install sbt. First add the necessary repository with the command:

echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list

Add the public key for the installation with the command:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823

Update apt with the command:

sudo apt-get update

Finally, install sbt with the command:

sudo apt-get install sbt -y

Once the installation is complete, test to make sure all is working with the command:

sbt test

This should report that a project definition is loaded (it's empty, of course) and should end with success (Figure B).

sbta.jpg

Figure B: Sbt is successfully installed.

Ready and waiting

And that's all there is to it. Sbt is now ready and waiting for you to build your first project. For more information on getting started with developing on sbt, check out the official sbt reference manual.

Also see

linuxhero.jpg

Jack Wallen

By Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.