Skip to content

Building Scala 3.x

aborkar-ibm edited this page Jul 27, 2021 · 27 revisions

Building Scala

Below versions of Scala are available in respective distributions at the time of creation of these build instructions:

  • Ubuntu (18.04, 20.04, 21.04) has 2.11.12-4
  • RHEL (8.2, 8.3, 8.4) has 2.10.6
  • SLES (15 SP2, 15 SP3) has 2.10.7

The instructions provided below specify the steps to build Scala version 3.0.0 on Linux on IBM Z Systems for following distributions:

  • RHEL (7.8, 7.9, 8.2, 8.3, 8.4)
  • SLES (12 SP5, 15 SP2, 15 SP3)
  • Ubuntu (18.04, 20.04, 21.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions. This is a temporary writable directory anywhere you'd like to place it.

Step 1: Build and Install Scala

1.1) Install the dependencies

export SOURCE_ROOT=/<source_root>/
  • RHEL (7.8, 7.9, 8.2, 8.3, 8.4)

    • With OpenJDK

      sudo yum install -y java-11-openjdk java-11-openjdk-devel wget
    • With AdoptOpenJDK

      sudo yum install -y tar wget
      • Download and install AdoptOpenJDK 11 (with HotSpot or with OpenJ9) from here.
  • SLES (12 SP5, 15 SP2, 15 SP3)

    • With OpenJDK

      sudo zypper install -y java-11-openjdk java-11-openjdk-devel wget
    • With AdoptOpenJDK

      sudo zypper install -y tar wget gzip
      • Download and install AdoptOpenJDK 11 (with HotSpot or with OpenJ9) from here.
  • Ubuntu (18.04, 20.04, 21.04)

    • With OpenJDK

      sudo apt-get update
      sudo apt-get install -y wget openjdk-11-jdk openjdk-11-jdk-headless
    • With AdoptOpenJDK

      sudo apt-get update
      sudo apt-get install -y wget tar gzip
      
      • Download and install AdoptOpenJDK 11 (with HotSpot or with OpenJ9) from here.

Note: At the time of creation of these build instructions, Scala 3.0.0 was verified with OpenJDK 11 (build 11.0.11+9-LTS) on RHEL, OpenJDK 11 (build 11.0.11+9-Ubuntu) on Ubuntu, OpenJDK 11 (build 11.0.11+9-suse-3.56.1) on SLES 15 SP2 & SLES 15 SP3, OpenJDK 11 (build 11.0.11+9-suse-3.15.1) on SLES 12 SP5, AdoptOpenJDK 11 with HotSpot (build 11.0.11+9) and AdoptOpenJDK 11 with OpenJ9 (build openj9-0.26.0).

1.2) Set Environment Variables

export JAVA_HOME=<Path to Java>
export PATH=$JAVA_HOME/bin:$PATH

1.3) Download and Install Scala

cd $SOURCE_ROOT
wget https://github.com/lampepfl/dotty/releases/download/3.0.1/scala3-3.0.1.tar.gz
tar -xvf scala3-3.0.1.tar.gz
export PATH=$SOURCE_ROOT/scala3-3.0.1/bin:$PATH

Check Scala version by using the following command

scala -version
scalac -version
Scala compiler version 3.0.1 -- Copyright 2002-2021, LAMP/EPFL.

Step 2: [Optional] Testing Scala Sample Program

2.1) Create a test program

Create a test file called Hello.scala using below command:

echo '@main def hello = println("Hello, world!")' > Hello.scala

2.2) Compile the test program

scalac Hello.scala

Note: This will create several files:

Hello$package$.class
Hello$package.class
Hello$package.tasty
Hello.scala
hello.class
hello.tasty

2.3) Execute the test program

scala hello

The output of the above test program should be:

Hello, world!

Note: For addition information on Getting Started with Scala, visit here

References

Clone this wiki locally