Scala Foundation Course - Installing SBT


In this lesson, I want to give you a quick introduction to SBT. I will also demonstrate SBT installation and configuration on a Linux machine. So, let’s start.
SBT is a build tool for Scala projects. You can use it for Java as well. It serves the same purpose as Apache Maven, but I find it too simple for small projects. That's why the name SBT stands as a simple build tool. I liked it most for a couple of reasons.

  1. We need very little or no configuration for simple projects, and it saves you from those complex XML syntaxes used in Maven.
  2. You don't need to install Scala separately, and you can start Scala REPL on your project. Scala REPL (Read–Eval–Print Loop) is a command line tool where you can execute Scala code line by line as an interactive command.

There are many other features, and we will explore the most relevant ones as we progress. The first thing is to install and configure SBT and explore some basic operations.
Installing SBT is a two-step process.

  1. Download and Install JDK.
  2. Download and install SBT.

Installing JDK

  1. Download JDK rpm from oracle technology network. I recommend downloading rpm package.
  2. Once you have the rpm, you can install it using yum localinstall <rpm-package> command.
  3. Verify your installation using Java -version Command.
  4. You should also set JAVA_HOME and PATH environment variables. I prefer to place them in /etc/profile.

Installing SBT

  1. Download the SBT Launcher jar file and place it in the /usr/local/bin directory.
  2. Create the script to launch sbt and place it in /usr/local/bin with following content.

File name - sbt

  1. Give execute permission to sbt file.

Now, you are ready to start SBT. But before that, create a workspace directory for all your SBT projects. Change to the project directory. Your project folder may be empty, but that's not a problem. You can start SBT with an empty project. Before you start SBT, you should change your current directory to your project directory. It is a recommended practice because SBT considers your current directory as your base project directory and set the current project to the current directory.
Just type SBT and hit the enter key. For the first time, it will take few minutes because it downloads necessary things to complete your installation. It also compiles your current project, but in our case, we have nothing to compile.
That’s it. You should get the SBT command prompt. SBT Installation is complete, and you are now ready to use SBT as well as Scala.
Thank you for visiting Learning Journal.



You will also like: