Skip to content

Instantly share code, notes, and snippets.

@ricardozanini
Last active February 22, 2024 20:59
Show Gist options
  • Star 42 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save ricardozanini/fa65e485251913e1467837b1c5a8ed28 to your computer and use it in GitHub Desktop.
Save ricardozanini/fa65e485251913e1467837b1c5a8ed28 to your computer and use it in GitHub Desktop.
How to install GraalVM on Linux with alternatives

How to Install GraalVM Community Edition on Linux

Note: Tested on Fedora only

  1. Download the new release of GraalVM and unpack it anywhere in your filesystem:
$ tar -xvzf graalvm-ce-1.0.0-rc14-linux-amd64.tar.gz
  1. 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-1.0.0-rc14/ /usr/lib/jvm/
# cd /usr/lib/jvm
# ln -s graalvm-ce-1.0.0-rc14 graalvm
  1. 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:
# alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.2.7-0.fc29.x86_64/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.fc29.x86_64/jre/bin/java)
   3           java-openjdk.x86_64 (/usr/lib/jvm/java-12-openjdk-12.0.0.33-1.ea.1.rolling.fc29.x86_64/bin/java)

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

# alternatives --install /usr/bin/java java /usr/lib/jvm/graalvm/bin/java 4

Testing

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

[ricferna@skywalker Downloads]$ sudo alternatives --config java

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.2.7-0.fc29.x86_64/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.fc29.x86_64/jre/bin/java)
   3           java-openjdk.x86_64 (/usr/lib/jvm/java-12-openjdk-12.0.0.33-1.ea.1.rolling.fc29.x86_64/bin/java)
   4           /usr/lib/jvm/graalvm/bin/java

Enter to keep the current selection[+], or type selection number: 4

To verify, just check the version number:

[ricferna@skywalker Downloads]$ java -version
openjdk version "1.8.0_202"
OpenJDK Runtime Environment (build 1.8.0_202-20190206132807.buildslave.jdk8u-src-tar--b08)
OpenJDK GraalVM CE 1.0.0-rc14 (build 25.202-b08-jvmci-0.56, mixed 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.

@r4lly99
Copy link

r4lly99 commented Jun 16, 2020

Thanks you @ricardozanini

@perico1964
Copy link

Thanks.

@serefarikan
Copy link

worked like a charm under Ubuntu 18.04 (with update-alternatives). for some reason, the 4 means priority under Ubuntu, not the order, but other than that, all good. thanks for sharing this.

@loominatrx
Copy link

loominatrx commented Sep 11, 2022

Since alternatives is not available on arch, do you have any other solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment