Get Started with GraalVM on Oracle Linux in OCI

Send lab feedback

Get Started with GraalVM Enterprise on Oracle Linux in OCI


This hands-on lab shows how to install GraalVM Enterprise and its features on Oracle Linux in Oracle Cloud Infrastructure.

  GraalVM Enterprise is included in the Oracle Java SE Subscription and available at no cost on Oracle Cloud Infrastructure (OCI)

GraalVM Enterprise is a high performance JDK distribution, built on trusted and secure Oracle Java SE, designed to accelerate application performance while consuming fewer resources. Faster applications with lower resource requirements translates into fewer or smaller servers, which reduces cloud costs.

GraalVM Enterprise offers two ways to run Java applications: on the HotSpot JVM with Graal just-in-time (JIT) compiler or as an ahead-of-time (AOT) compiled native exectuable.

Lab Contents

In this lab you will:

  • Connect to a VM instance in Oracle Cloud
  • Install GraalVM Enterprise on Oracle Linux
  • Add additional GraalVM Enterprise features (Native Image)
  • Update an existing GraalVM Enterprise installation

Estimated Workshop Time: 20 minutes

NOTE: To copy the command, hover over the field and then click the copy to clipboard icon.

Task 1: Connect to a VM instance in Oracle Cloud

When you launch the lab, the necessary resources are provisioned in the background: Virtual Cloud Network (VCN) and a Compute Instance with the Oracle Linux 8 pre-built image. It can take 1-2 minutes to complete provisioning. You can tell when the resources are fully provisioned and ready by consulting the Resources tab on the Luna Lab webpage (see step 1, below).

  1. Double-click the Luna Lab icon on the desktop to open the browser.

    Wait until the the animated gear besides Resources turns into a checkmark. It means all the required compute and network resources are provisioned and you can proceed.

  2. Unfold Resources and copy the Public IP address from the SERVER_IP box. You many need to click on View Details. You can use the Copy to clipboard button on the far right that appears when you hover over the box.

  3. Minimize the browser window so you can see the Luna Desktop. Click the Applications menu and open a Terminal Emulator.

  4. Enter SSH connection command where <SERVER_IP> is your VM instance public IP address:

    ssh opc@<SERVER_IP>

    Accept the ECDSA key fingerprint by typing yes at the prompt.

You are now connected to a remote host in Oracle Cloud and can proceed to the next task.

Task 2: Install GraalVM Enterprise Oracle Linux

In this task you will install GraalVM Enterprise on Oracle Linux and set it as a default Java runtime.

For convenient installation, GraalVM Enterprise RPMs are available in the Oracle Linux YUM repository, which means OCI users can install GraalVM Enterprise in their cloud instances using yum — a package-management utility for the Linux operating systems.

  1. (Optional) In the terminal window connected to a VM instance, search for available GraalVM Enterprise packages, narrowing down the search to a specific release and Java 11:

    sudo yum provides graalvm21-ee-11-jdk

    The resulting list includes both current and previous versions of Oracle GraalVM Enterprise Edition JDK11 Java Development Kit version 21.x.

  2. Install graalvm21-ee-11-jdk:

    sudo yum install graalvm21-ee-11-jdk

    Confirm if the installed package size is okay by typing yes at the prompt. It will install the latest version of graalvm21-ee-11-jdk which includes the JVM runtime, the Graal compiler, and all dependent packages, for example, libpolyglot, llvm, etc.

  3. Configure environment variables to point to the GraalVM Enterprise installation for this SSH session. After the installation, the package files are placed in the /usr/lib64/graalvm directory, and binaries in bin accordingly.

    • Set the PATH and JAVA_HOME environment variables in the bash configuration to point to GraalVM Enterprise with the following commands:

      echo "export JAVA_HOME=/usr/lib64/graalvm/graalvm21-ee-11" >> ~/.bashrc
      echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
    • Activate this change:

      source ~/.bashrc
  4. Check the Java version to see if the installation was successful and the JDK is set to GraalVM Enterprise:

    java -version

At this point you can already run any Java workload on GraalVM Enterprise with no code changes required. GraalVM Enterprise employs the Graal optimizing compiler as the top-tier JIT compiler which performs advanced optimization and applies aggressive inlining techniques to accelerate application performance.

We recommend you to take the Accelerate Applications in Oracle Cloud with GraalVM Enterprise lab upon this lab completion. That lab focuses on comparing the performance of the Graal JIT compiler vs. C2 while running a Java Microbenchmark Harness (JMH).

You can proceed to the next task.

Task 3: Add additional GraalVM Enterprise Features (Native Image)

GraalVM Enterprise is shipped with core components (to save the filesize) and can be extended with more features on demand. For example, you can install Native Image, the Node.js runtime, the LLVM toolchain, etc. Check the product documentation for more information on available features .

To add additional features to GraalVM Enterprise, the yum install <package_name> command is sufficient. In this task, you will install GraalVM Enterprise's Native Image , a technology to ahead-of-time compile Java code to a standalone native executable.

  1. (Optional) Check what additional features are available for your current GraalVM Enterprise installation:

    sudo yum provides graalvm21*

    The printed list is enormous. Since you are interested in the Native Image component, narrow down the search providing the exact package name:

    sudo yum provides graalvm21-ee-11-native-image*
  2. Install Native Image by running these commands one by one (Oracle Linux 8 specific):

    sudo yum update -y oraclelinux-release-el8

    It will update the local repo metadata cache to get new available packages.

    sudo yum config-manager --set-enabled ol8_codeready_builder

    It will enable the ol8_codeready_builder repository containing some of Native Image dependencies.

    sudo yum install graalvm21-ee-11-native-image

    Confirm if the installed package size is okay by typing yes at the prompt. It will install all the required dependent libraries (e.g., glibc, zlib, etc.) and place the native-image utility in the GraalVM Enterprise installation directory ($JAVA_HOME/bin).

      On Oracle Linux 7, it is enough to run sudo yum install graalvm21-ee-11-native-image to install Native Image.

  3. Check the version to see if the installation was successful:

    native-image --version

Now you can start using the native-image utility to transform your Java application into a native Linux executable. Running a Java application as a native executable provides instantaneous startup, lower CPU and memory consumption, making it a good candidate for cloud deployments.

We recommend you to take the GraalVM Native Image Quick Start lab upon this lab completion to get hands-on lab experience using GraalVM Native Image and start building cloud native Java applications.

You can proceed to the next task.

Task 4: Update an Existing GraalVM Enterprise Installation

The yum package manager for Oracle Linux can be used to update an existing GraalVM Enterprise installation or replace it with another version. In this task you will update GraalVM Enterprise from version 21.x to 22.x, and replace the distribution for Java 11 with GraalVM Enterprise for Java 17.

  1. Update GraalVM Enterprise from version 21.x to 22.x and install the distribution for Java 17 instead of Java 11:

    sudo yum install graalvm22-ee-17-jdk

    Confirm if the installed package size is okay by typing yes at the prompt.

  2. Check the Java version to see if the update was successful:

    java -version

    The graalvm22-ee-17-jdk package was installed alongside graalvm21-ee-11-jdk in the /usr/lib64/graalvm directory and the whole system was updated:

    Note: Regardless the version printed to the console, the PATH and JAVA_HOME environment variables still point to the old version. Reset the variables as described in Task 2, step 3.

Note on the yum upgrade command

The yum upgrade command can be used to update on the same year package line, for example, to upgrade from GraalVM Enterprise 22.0.0 to version 22.0.1 when this RPM package becomes available:

sudo yum upgrade graalvm22-ee-17-jdk

It will update the whole system and remove the obsolete GraalVM Enterprise installation.

Congratulations! You have successfully completed this lab.

Learn More

To end this session, click the End Session button in the toolbar.