Skip to content

Building Scala 3.x

linuxonz edited this page Dec 31, 2024 · 22 revisions

Building Scala

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

  • Ubuntu 20.04 has 2.11.12-4
  • Ubuntu (22.04, 24.04, 24.10) have 2.11.12-5
  • RHEL (8.8, 8.10) have 2.10.6
  • SLES 15 SP6 has 2.10.7

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

  • RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
  • SLES 15 SP6
  • Ubuntu (20.04, 22.04, 24.04, 24.10)

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.

1. Build and Install Scala

1.1. Install the build dependencies

export SOURCE_ROOT=/<source_root>/
  • RHEL (8.8, 8.10, 9.2, 9.4, 9.5)

    sudo yum install -y tar wget curl diffutils gcc make
    
  • SLES 15 SP6

    sudo zypper install -y wget tar gzip curl gawk gcc make
    
  • Ubuntu (20.04, 22.04, 24.04, 24.10)

    sudo apt-get update
    sudo apt-get install -y tar wget curl gzip gcc make
    

1.2. Install java

  • With IBM Semeru Runtime

    • Download and install IBM Semeru Runtime (Java 8 or 11 or 17 or 21) from here.
  • With Eclipse Adoptium Temurin Runtime

    • Download and install Eclipse Adoptium Temurin Runtime (Java 11 or 17 or 21) from here.
  • Download and install AdoptOpenJDK8 from here

  • With OpenJDK 8

    • RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
      sudo yum install -y java-1.8.0-openjdk-devel 
    • SLES 15 SP6
      sudo zypper install -y java-1_8_0-openjdk-devel
    • Ubuntu (20.04, 22.04, 24.04, 24.10)
      sudo apt-get install -y openjdk-8-jdk
  • With OpenJDK 11

    • RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
      sudo yum install -y java-11-openjdk-devel 
    • SLES 15 SP6
      sudo zypper install -y java-11-openjdk-devel
    • Ubuntu (20.04, 22.04, 24.04, 24.10)
      sudo apt-get install -y openjdk-11-jdk
  • With OpenJDK 17

    • RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
      sudo yum install -y java-17-openjdk-devel 
    • SLES 15 SP6
      sudo zypper install -y --auto-agree-with-licenses java-17-openjdk java-17-openjdk-devel
    • Ubuntu (20.04, 22.04, 24.04, 24.10)
      sudo apt-get install -y openjdk-17-jdk
  • With OpenJDK 21

    • RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
      sudo yum install -y java-21-openjdk-devel
    • SLES 15 SP6
      sudo zypper install -y --auto-agree-with-licenses java-21-openjdk java-21-openjdk-devel
    • Ubuntu (20.04, 22.04, 24.04, 24.10)
      sudo apt-get install -y openjdk-21-jdk

Note: At the time of creation of these build instructions, Scala 3.3.4 was verified with
OpenJDK 1.8.0, 11.0.19, 17.0.7, 21.0.2
IBM Semeru Runtime Open Edition 1.8.0_372-b07, 11.0.19.0, 17.0.7.0 and 21.0.2
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_282-b08)
Eclipse Adoptium Temurin-11.0.19+7, 17.0.7.0, 21.0.2

1.3. Build libffi library (For AdoptOpenJDK8 on Ubuntu, SLES and RHEL 9.x)

cd $SOURCE_ROOT/
wget ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz
tar xvfz libffi-3.2.1.tar.gz
cd libffi-3.2.1
./configure --prefix=/usr/local
make
sudo make install
sudo ldconfig
sudo ldconfig /usr/local/lib64

1.4. Set Environment Variables

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

1.5. Download and Install Scala

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

Check Scala version by using the following command

scala -version
scalac -version
Scala code runner version 3.3.4 -- Copyright 2002-2024, LAMP/EPFL
Scala compiler version 3.3.4 -- Copyright 2002-2024, LAMP/EPFL

2. Testing Scala Sample Program (Optional)

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