BYO: GraalVM Setup - Hello World

Arpit RathoreArpit Rathore
2 min read

In this blog, we will setup local development environment for native Java using Graal VM. For this we will use following tools

  1. Ubuntu 24.04

  2. Sdkman

  3. GraalVM 21

  4. Maven

Code used in this blog: link

Install sdkman

$ lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:    24.04
Codename:    noble

$ curl -s "https://get.sdkman.io" | bash

Output:

All done!


You are subscribed to the STABLE channel.

Please open a new terminal, or run the following in the existing one:

    source "/home/arpit/.sdkman/bin/sdkman-init.sh"

Then issue the following command:

    sdk help

Enjoy!!!

Install GraalVM Prerequisites

# Open a new terminal (Otherwise the command `sdk` will not be available)
# Install prerequisites for GraalVM
$ sudo apt-get install -y build-essential zlib1g-dev

Install GraalVM 21

# List available java versions
$ sdk list java
================================================================================
Available Java Versions for Linux ARM 64bit
================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier
--------------------------------------------------------------------------------
 Corretto      |     | 23.0.1       | amzn    |            | 23.0.1-amzn
               |     | 21.0.5       | amzn    |            | 21.0.5-amzn
               |     | 17.0.13      | amzn    |            | 17.0.13-amzn
               |     | 11.0.25      | amzn    |            | 11.0.25-amzn
               |     | 8.0.432      | amzn    |            | 8.0.432-amzn
 GraalVM CE    |     | 23.0.1       | graalce |            | 23.0.1-graalce
               |     | 21.0.2       | graalce |            | 21.0.2-graalce
               |     | 17.0.9       | graalce |            | 17.0.9-graalce

# Install GraalVM 21
$ sdk install java 21.0.2-graalce

Output

.
.
Installing: java 21.0.2-graalce
Done installing!


Setting java 21.0.2-graalce as default.

Install Maven

$ sdk install maven

Clone the project and build

# Clone the base project
$ git clone https://github.com/arpitrathore/build-your-own
$ cd build-your-own/01-hello-world/

# Build the `ar-helloworld` native binary using maven and GraalVM Plugin
$ mvn clean package -Pnative

Output

Produced artifacts:
 /home/arpit/build-your-own/01-hello-world/target/ar-helloworld (executable)
========================================================================================================================
Finished generating 'ar-helloworld' in 56.2s.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:00 min
[INFO] Finished at: 2025-01-05T00:11:36+05:30
[INFO] ------------------------------------------------------------------------

Test the binary

$ ./target/ar-helloworld                                                                                   130 main130 main
Hello World! Current time is: 2025-01-05T00:12:52.436238
0
Subscribe to my newsletter

Read articles from Arpit Rathore directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arpit Rathore
Arpit Rathore

Senior Backend Engineer