DEV Community

Fahad Israr
Fahad Israr

Posted on

19 1

Guide to Install GraalVM Community Edition on Ubuntu

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

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (2)

Collapse
 
friendbear profile image
T Kumagai

It's Worked

$ uname -a
Linux tubasan 5.11.0-1017-raspi #18-Ubuntu SMP PREEMPT Mon Aug 23 07:34:31 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-arm64/bin/java   1111      auto mode
* 1            /usr/lib/jvm/graalvm/bin/java                 1         manual mode
  2            /usr/lib/jvm/java-11-openjdk-arm64/bin/java   1111      manual mode

Press <enter> to keep the current choice[*], or type selection number: 1

Enter fullscreen mode Exit fullscreen mode
Collapse
 
sam_54 profile image
Dmitry Samoylenko

Good article which use update-alternatives

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay