JAVA_HOME to JDK not JRE error? Compiler is not provided on Big Sur?

Gheorghe Madalina Eleonora
2 min readJun 9, 2021

First of all, find what java version is available on your machine by entering this command in your cmd. The output will contain your virtual machines, where one of them will be your path to your java version.

/usr/libexec/java_home -V

In my case, my version is 1.8.0, for Java SE 8.

Matching Java Virtual Machines (2):1.8.281.09 (x86_64) “Oracle Corporation” — “Java” /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home1.8.0_261 (x86_64) “Oracle Corporation” — “Java SE 8” /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

Error 1. JAVA_HOME needs to point to a JDK not a JRE:

The JAVA_HOME environment variable is not defined correctly.
This environment variable is needed to run this program.
NB: JAVA_HOME should point to a JDK not a JRE

The solution:

Enter the .zshrc file.

vim ~/.zshrc

Press i to insert and add your path to JAVA_HOME version.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home

Press control+c to exit the insert mode and type :wq to write the document and quit it. Now you have to source it.

source ~/.zshrc

Expected output on echo $JAVA_HOME:

/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Homeexport JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)

Error 2. Compiler is not provided:

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

The solution:

Maven reads JAVA_HOME from ~/.mavenrc instead of ~/.zshrc.

Enter the .mavenrc file.

vim ~/.mavenrc

Press i to insert and add your path to JAVA_HOME version.

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)

Press control+c to exit the insert mode and type :wq to write the document and quit it. Now you have to source it.

source ~/.mavenrc

Expected output mvn -version:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 1.8.0_261, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: “mac os x”, version: “10.16”, arch: “x86_64”, family: “mac”

--

--

Gheorghe Madalina Eleonora

✨ Passionate photographer and FE Developer @Cognizant, former FE Developer at @Deloitte Digital and @IBM.