GraalVM Installation and Usage Guide | Generated by AI
What is GraalVM?
GraalVM is an open-source high-performance runtime (JDK distribution) that supports multiple programming languages like Java, JavaScript, Python, and more. It features an advanced JIT compiler for faster execution and the ability to compile Java applications to native executables via Native Image, reducing startup time and memory footprint.
Installation
- Download GraalVM:
- Go to the official GraalVM downloads page.
- Choose the Community Edition (free) or Oracle GraalVM (with additional features).
- Select the version for your platform (e.g., Linux, macOS, Windows) and architecture (x64 or ARM).
- As of 2025, the latest stable release is GraalVM for JDK 22 or 23—check the site for the most current.
- Extract and Install:
- Unzip the downloaded archive to a directory, e.g.,
/opt/graalvmon Linux/macOS orC:\Program Files\GraalVMon Windows. - No installer is needed; it’s a portable distribution.
- Unzip the downloaded archive to a directory, e.g.,
- Set Environment Variables:
- Set
JAVA_HOMEto the GraalVM directory (e.g.,export JAVA_HOME=/opt/graalvmon Linux/macOS). - Add the
bindirectory to yourPATH(e.g.,export PATH=$JAVA_HOME/bin:$PATH). - Verify with
java -version; it should show GraalVM details.
- Set
- Install Additional Components (Optional):
- Use
gu(GraalVM Updater) for language runtimes or Native Image:gu install native-image(requires build tools likebuild-essentialon Linux).
- Use
Building a Hello World Program
We’ll use Java for this example, as it’s GraalVM’s primary language. Create a simple “Hello World” app, compile it, and run it.
Step 1: Write the Code
Create a file named HelloWorld.java:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World from GraalVM!");
}
}
Step 2: Compile
Open a terminal in the directory with the file and run:
javac HelloWorld.java
This produces HelloWorld.class.
Step 3: Run
java HelloWorld
Output:
Hello, World from GraalVM!
Advanced: Compile to Native Executable
GraalVM’s Native Image feature lets you build a standalone binary.
- Ensure Native Image is installed:
gu install native-image. - Generate a configuration (first run may require this):
native-image --no-fallback -H:+ReportExceptionStackTraces HelloWorld- This creates
HelloWorld(orhelloworld.exeon Windows), a native binary. - On first build, it analyzes the app and may take a few minutes.
- This creates
- Run the native binary:
./HelloWorldOutput is the same, but it starts instantly with low memory use.
Tips for Using GraalVM
- Switching JDKs: Use SDKMAN! (
sdk install java 22.0.2-graal) for easy management. - Multi-Language: Run Node.js code with
nodefrom GraalVM, or Python withpython. - Performance: Enable GraalVM’s JIT with
-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler. - Troubleshooting: Check logs in
~/.gu/for issues; ensure your system has a C compiler for Native Image.
For more details, see the official docs.
GraalVM Downloads
GraalVM User Guide
Native Image Tutorial