DEV Community

loading...

Guide to Install GraalVM Community Edition on Ubuntu

fahadisrar profile image Fahad Israr ・2 min read

1) Download the latest release of GraalVM and unpack it anywhere in your filesystem:

Note: GraalVM Community Edition 19.3.0 and later releases can be found here

$ tar -xvzf graalvm-ce-java11-linux-amd64-20.0.0.tar.gz
Enter fullscreen mode Exit fullscreen mode

2) Move the unpacked dir to /usr/lib/jvm/ and create a symbolic link to make your life easier when updating the GraalVM version:

# mv graalvm-ce-java11-linux-amd64-20.0.0/ /usr/lib/jvm/
# cd /usr/lib/jvm
# ln -s graalvm-ce-java11-linux-amd64-20.0.0 graalvm
Enter fullscreen mode Exit fullscreen mode

3) Add a new alternatives configuration. First grab the priorization number by listing the already installed JVMs and then use this number to configure the new one:

# update-alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
  *1           /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
Enter fullscreen mode Exit fullscreen mode

In this case I have 2 java alternatives installed, so I'm going to install the third.

# sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/graalvm/bin/java 2
Enter fullscreen mode Exit fullscreen mode

Testing

To make sure everything is working fine, set the new JVM on your environment:

$ sudo update-alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
 *1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
  2            /usr/lib/jvm/graalvm-ce-java11-20.0.0/bin/java   4         manual mode

Enter to keep the current selection[+], or type selection number: 2
Enter fullscreen mode Exit fullscreen mode

To verify, just check the version number:

$ java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02)
OpenJDK 64-Bit Server VM GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02, mixed mode, sharing)

Enter fullscreen mode Exit fullscreen mode

And you're set.

Note

The native-image executable is not bundled in the GraalVM distribution anymore. Install it manually using $GRAALVM_HOME/bin/gu install native-image.

Unable to use gu command??

Solution: Export path in bashrc file

Steps:

  • Open bashrc file: sudo nano ~/.bashrc

  • At the end add this: export PATH=$PATH:/usr/lib/jvm/graalvm-ce-java11-20.0.0/lib/installer/bin

Note: You may use the suitable path as per your installation

After that you may try running gu again: gu install native-image

Still Unable to use native-image??

Do the same for native-image:Add this to bashrc file for native-image

export PATH=$PATH:/usr/lib/jvm/graalvm-ce-java11-20.0.0/lib/svm/bin

To use the commands as Super User:

Add this to /root/.bashrc and /root/.profile:

  • Open bashrc for root sudo nano /root/.bashrc
  • Add these at the end :
  export PATH=$PATH:/usr/lib/jvm/graalvm-ce-java11-20.0.0/lib/installer/bin
  export PATH=$PATH:/usr/lib/jvm/graalvm-ce-java11-20.0.0/lib/svm/bin

Enter fullscreen mode Exit fullscreen mode
  • Do the same for profile: sudo nano /root/profile

Discussion (1)

pic
Editor guide