Install GraalVM and Native-Image on a Mac
Published
Updated
The GraalVM documentation is not very helpful when it comes to installing the updater and other tools on a Mac device. This will guide you on the easiest way to install GraalVM along with the Native Image plugin on your MacOS devices.
Install GraalVM using Homebrew
You can easily install the GraalVM Java Virtual Machine and libraries using the following brew install commands:
For Java 8
brew install --cask graalvm/tap/graalvm-ce-java8
For Java 11
brew install --cask graalvm/tap/graalvm-ce-java11
You then need to add the JVM to your JAVA_HOME path so that it is used for compilation:
For Java 8
export JAVA_HOME=$HOME/Library/Java/JavaVirtualMachines/graalvm-ce-java8-21.0.0.2/Contents/Home
For Java 11
export JAVA_HOME=$HOME/Library/Java/JavaVirtualMachines/graalvm-ce-java11-21.0.0.2/Contents/Home
Finally, if you try to run the GraalVM JVM, you will notice MacOS will give you the following error or a developer cannot be verified error:
"graalvm-ce-java8-21.0.0.2" is damaged and can't be opened.
You can fix this by running the following:
xattr -r -d com.apple.quarantine /Library/Java/JavaVirtualMachines/graalvm-ce-java8-21.0.0.2
For Java 11
xattr -r -d com.apple.quarantine /Library/Java/JavaVirtualMachines/graalvm-ce-java11-21.0.0.2
Or Install GraalVM using SDKMan
Alternatively, you can use SDKMan to install and configure GraalVM. To start, you will need to install SDKMan. This is a command line utility which lets you easily configure packages for Java and a few other programming environments.
Once installed, you will have the sdk
command available to you on the command line. Open a terminal and run one of the following:
For Java 8:
sdk install java 21.0.0.r8-grl
For Java 11
sdk install java 21.0.0.r11-grl
At this point you can now configure your Java HOME path to point to your GraalVM Java installation:
For Java 8
export JAVA_HOME=$HOME/.sdkman/candidates/java/21.0.0.r8-grl
For Java 11
export JAVA_HOME=$HOME/.sdkman/candidates/java/21.0.0.r11-grl
Corporate Proxy Configuration
If you are behind a corporate proxy, you will need to configure your installation with a few more steps. If you have a custom certificate that is provided by your organization, you can import the .cer file into your GraalVM trust store using the following command:
keytool -v -import -file yourProxyCertificate.cer -alias aliasForCert -keystore $JAVA_HOME/jre/lib/security/cacerts
When prompted for a password, use: changeit
.
Installing the Native Image Plugin for GraalVM
You should now have the ability to install the native image plugin using the gu
command on your terminal. Run the following if you are not behind a proxy:
gu install native-image
If you get the error gu: command not found
, you need to make sure the GraalVM Updater component is on your PATH. Do so with the following command:
export PATH=/Library/Java/JavaVirtualMachines/graalvm-ce-java8-21.0.0.2/Contents/Home/bin:"$PATH"
If you are using Java 11, change the above java8
to java11
.
The following command is how to install the Native Image Plugin if you have a corporate proxy:
gu --jvm \
--vm.Dcom.sun.net.ssl.checkRevocation=false \
--vm.Dhttp.proxyHost=proxy.mycompany.com \
--vm.Dhttp.proxyPort=8080 \
--vm.Dhttp.proxyUser=proxyUsername \
--vm.Dhttp.proxyPass=proxyPassword \
--vm.Dhttps.proxyHost=proxy.mycompany.com \
--vm.Dhttps.proxyPort=8443 \
--vm.Dhttps.proxyUser=proxyUsername \
--vm.Dhttps.proxyPass=proxyPassword \
install native-image
That should now let you install the GraalVM plugin even though you are behind a proxy.