# BYO: GraalVM Setup - Hello World

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](https://github.com/arpitrathore/build-your-own/tree/main/01-hello-world)

## Install [sdkman](https://sdkman.io/)

```bash
$ 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:

```plaintext
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](https://www.graalvm.org/latest/getting-started/linux/)

```bash
# 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

```bash
# 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

```plaintext
.
.
Installing: java 21.0.2-graalce
Done installing!


Setting java 21.0.2-graalce as default.
```

## Install Maven

```bash
$ sdk install maven
```

## Clone the [project](https://github.com/arpitrathore/build-your-own) and build

```bash
# 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

```plaintext
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

```bash
$ ./target/ar-helloworld                                                                                   130 main130 main
Hello World! Current time is: 2025-01-05T00:12:52.436238
```
