The problem that you are seeing is because jenv is not setup properly for your terminal. Depending on your terminal, you should look at your .bash_profile or .zshrc and ensure that the following lines exist:

Copyexport PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

You can test to see if jenv has been initialized properly in your terminal by running which java. If jenv is initialized properly you will see something like:

Copy/Users/your-username/.jenv/shims/java

If you don't see this, double check .bash_profile or .zshrc as described above. I also recommend that you place these at the end of the file so that you can be sure that jenv gets added onto the start of your PATH.

The magic behind jenv is jenv init. When you open your terminal this runs and updates your PATH to look at ~/.jenv/shims which contains a shim (shell script) which resolves your desired version of Java when you run java or other JRE/JDK commands.

Answer from Blaine on Stack Overflow
🌐
Jenv
jenv.be
jEnv - Manage your Java environment
jEnv is a command line tool to help you forget how to set the JAVA_HOME environment variable · Further Documentation
🌐
GitHub
github.com › jenv › jenv › issues › 212
not setting a version on mac · Issue #212 · jenv/jenv
August 30, 2018 - # g.reshetniak @ MP24502 in ~/edge on git:master x [11:24:27] $ jenv versions system * 1.7 (set by /Users/g.reshetniak/edge/.java-version) 1.7.0.181 1.8 1.8.0.181 openjdk64-1.7.0.181 oracle64-1.8.0.181 # g.reshetniak @ MP24502 in ~/edge on git:master x [11:24:33] $ jenv global 1.7 # g.reshetniak @ MP24502 in ~/edge on git:master x [11:24:50] $ java --version java 10.0.2 2018-07-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode) # g.reshetniak @ MP24502 in ~/edge on git:master x [11:24:53] $ jenv local 1.7 # g.reshetniak @ MP24502 in ~/edge on git:master x [11:26:31] $ java --version java 10.0.2 2018-07-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode) Seems like basic functionality, but it does not work as expected for me.
Author   jenv
Discussions

java - Not able to change the JDK in Mac OS using Jenv - Stack Overflow
I am trying Face recognizing in ... file not found error when i try to use CascadeClassifier xml file ... 0 .zshrc JAVA_HOME returning blank on new terminal but works when do source explicitly mac OS (catalina) ... 5 I install java7 and java8 using Jenv. Then, run "jenv global ... More on stackoverflow.com
🌐 stackoverflow.com
JAVA_HOME not exported properly
After installing, and adding jdk's 8 and 9, then setting jenv global to 1.8, I get expected results when issuing jenv info java. java -version also outputs expected results. However, other tool... More on github.com
🌐 github.com
16
February 14, 2018
【Invalid switch】jenv global not work
【Invalid switch】jenv global not work#239 · Copy link · HyWell · opened · on Mar 7, 2019 · Issue body actions · Reactions are currently unavailable · No one assigned · No labels · No labels · No type · Give feedback · No fields configured for issues without a type. More on github.com
🌐 github.com
0
March 7, 2019
terminal - Can't set different Java version in Mojave with jenv - Ask Different
Bring the best of human thought ... at your work. Explore Stack Internal ... I want to have different Java versions on my machine. I installed jenv for that reason. However, I can't set the desired Java version to it. Actually couldn't set any version. I have Java 8 and 11 installed. I want to set Java 8 as a global.... More on apple.stackexchange.com
🌐 apple.stackexchange.com
🌐
GitHub
github.com › jenv › jenv › issues › 339
JAVA_HOME not set on apple m1 · Issue #339 · jenv/jenv
October 20, 2021 - 1. brew install jenv 2. echo eval "$(jenv init -)" >> /Users/xiquan/.zshrc 3. jenv add $(/usr/libexec/java_home) 4. jenv global 1.8 5. <open new terminal tab> 6. echo ${JAVA_HOME} The intel MBP works fine while the m1 MBA not.
Author   jenv
🌐
Between Two Parens
betweentwoparens.com › blog › jenv
Manage your Java JDKs - Between Two Parens
January 1, 2020 - That's everything involved in setting a global version of JDK through jEnv. If for any reason you feel like something went wrong while installing jenv, or maybe you just don't like jEnv and you want to cleanup your environment the following steps will help you remove it. ... That's everything involved in setting up and working ...
🌐
MungingData
mungingdata.com › java › jenv-multiple-versions-java
Running Multiple Versions of Java on MacOS with jenv - MungingData
brew cask install caskroom/versions/adoptopenjdk8 also used to work, but now returns Error: caskroom/versions was moved. Tap homebrew/cask-versions instead. Once Java is downloaded, we need to manually add it to jenv. List the Java virtual machines with ls -1 /Library/Java/JavaVirtualMachines. Add Java 8 to jenv with jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/. Set the global Java version on your computer with jenv global openjdk64-1.8.0.265.
Top answer
1 of 4
41

The problem that you are seeing is because jenv is not setup properly for your terminal. Depending on your terminal, you should look at your .bash_profile or .zshrc and ensure that the following lines exist:

Copyexport PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

You can test to see if jenv has been initialized properly in your terminal by running which java. If jenv is initialized properly you will see something like:

Copy/Users/your-username/.jenv/shims/java

If you don't see this, double check .bash_profile or .zshrc as described above. I also recommend that you place these at the end of the file so that you can be sure that jenv gets added onto the start of your PATH.

The magic behind jenv is jenv init. When you open your terminal this runs and updates your PATH to look at ~/.jenv/shims which contains a shim (shell script) which resolves your desired version of Java when you run java or other JRE/JDK commands.

2 of 4
4

Behind the scenes jenv uses the /Library/Java/JavaVirtualMachines directory.

Then you could also type /usr/libexec/java_home -V to show all the available JDKs and analyse your issue:

CopyMatching Java Virtual Machines (4): 
11.0.2_2-OracleJDK, x86_64: "Java SE 11.0.2" /Library/Java/JavaVirtualMachines/OracleJDK-jdk-11.0.2.jdk/Contents/Home 
11.0.2_1-OpenJDK, x86_64: "OpenJDK 11.0.2" /Library/Java/JavaVirtualMachines/OpenJDK-jdk-11.0.2.jdk/Contents/Home 
1.8.0_11, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home 
1.7.0_45, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home 

/Library/Java/JavaVirtualMachines/OracleJDK-jdk-11.0.2.jdk/Contents/Home

In this exemple export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) set the JDK 1.8 version.

Thus, you even could define the following aliases:

Copyjava11_OpenJDK_export='export JAVA_HOME=$(/usr/libexec/java_home -v 11.0.2_1-OpenJDK)'
java11_OracleJDK_export='export JAVA_HOME=$(/usr/libexec/java_home -v 11.0.2_2-OracleJDK)'
java7_export='export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)'
java8_export='export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)'

NB: The version to use after java_home -v is defined in each JDK installation in the Contents/Info.plist file section JVMVersion.

I changed it, to easily switch between the OpenJDK and the Oracle JDK:

Copy$ tail -5 /Library/Java/JavaVirtualMachines/OpenJDK-jdk-11.0.2.jdk/Contents/Info.plist | head -2
<key>JVMVersion</key>
<string>11.0.2_1-OpenJDK</string>

$ tail -5 /Library/Java/JavaVirtualMachines/OracleJDK-jdk-11.0.2.jdk/Contents/Info.plist | head -2
<key>JVMVersion</key>
<string>11.0.2_2-OracleJDK</string>

So, in your case as you have two 1.8 versions (1.8 and 1.8.0.252). It is more than likely that you should update their Contents/Info.plist file section JVMVersion.

🌐
Reflectoring
reflectoring.io › manage-jdks-with-jenv
Managing Multiple JDK Installations With jEnv
October 18, 2022 - Each time we call java now, jEnv looks for a .java-version file and if it finds one, starts the JDK version defined in that file. If it doesn’t find a .java-version file, it starts the globally configured JDK instead. So, if we call java via the command line, it will pick up a locally configured JDK now. Great! But tools like Maven or Gradle still use the system version of the JDK! Let’s see what we can do about that. Making Maven work with the local JDK defined by jEnv is easy.
🌐
GitHub
github.com › jenv › jenv › issues › 188
JAVA_HOME not exported properly · Issue #188 · jenv/jenv
February 14, 2018 - After installing, and adding jdk's 8 and 9, then setting jenv global to 1.8, I get expected results when issuing jenv info java. java -version also outputs expected results. However, other tools that rely on JAVA_HOME are failing, and incorrectly referencing the wrong java version's home.
Author   jenv
Find elsewhere
🌐
Bring
developer.bring.com › blog › configuring-jenv-the-right-way
Configuring jenv the right way – Bring Developer
July 27, 2018 - PS : If you get errors stating that the command enable-plugin is not found, you must restart your terminal and things should work properly thereafter. I had to run jenv enable-plugin export because my jenv was not able to control my JAVA_HOME.
🌐
GitHub
github.com › jenv › jenv › issues › 239
【Invalid switch】jenv global not work · Issue #239 · jenv/jenv
March 7, 2019 - 【Invalid switch】jenv global not work#239 · Copy link · HyWell · opened · on Mar 7, 2019 · Issue body actions · Reactions are currently unavailable · No one assigned · No labels · No labels · No type · Give feedback · No fields configured for issues without a type.
Author   jenv
🌐
Medium
medium.com › javarevisited › manage-java-versions-with-jenv-6b8228552661
Manage Java Versions with jEnv. Master your Java Environment | by Jayson GCS | Javarevisited | Medium
September 11, 2023 - # Switch the local directory to the desired Java version jenv local 11.0.20.1 # Verify the currently selected Java version cat .java-version ... There are also other ways to manage the Java version in the global and shell scope.
🌐
GitHub
github.com › jenv › jenv
GitHub - jenv/jenv: Manage your Java environment · GitHub
This will create a .java-version file we can check into Git for our projects, and jenv will load it correctly when a shell is started from this directory. ... Yes! Observe that JAVA_HOME is set to a valid shim directory - this is a result of enabling the export plugin. If you executed this commands inside your $HOME directory, you can now delete .java-version: ... Where multiple versions are set, the highest priority setting as above takes effect. For example if the global version was 17 and the shell version was 11, 11 would be used.
Starred by 6.6K users
Forked by 398 users
Languages   Shell 99.0% | Dockerfile 1.0%
🌐
Adam Gamboa G
blog.adamgamboa.dev › using-jenv-to-switch-jkd-versions
Using jEnv to switch JDK versions
December 24, 2021 - Finally, let’s enable some plugins to make it work with maven or gradle. This is the step that is not included in the official guide. $ jenv enable-plugin export $ jenv enable-plugin maven $ jenv enable-plugin gradle · That’s all, every thing is read to start using jEnv. We can verify the java version using the commands jenv global and java -version to verify the are using the same java version.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › jenv
Newest 'jenv' Questions - Stack Overflow
Recently I used the jenv VERSION control tool in Ubuntu16LTS. This is probably the first time I have used this tool. Once installed, I can switch versions using jenv local VERSION, but jenv global ...
🌐
GitHub
github.com › jenv › jenv › issues › 44
Jenv not setting JAVA_HOME · Issue #44 · jenv/jenv
February 27, 2014 - Did I miss something; i'm trying ... values but not the JAVA_HOME? ... Ians-MacBook-Pro:~ ian$ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home Ians-MacBook-Pro:~ ian$ jenv local oracle64-1.7.0.45 Ians-MacBook-Pro:~ ian$ jenv global oracle64-1.7.0.45 ...
Author   jenv
🌐
Javastreets
javastreets.com › blog › 2017 › 9 › using_multiple_java_sdk_versions.html
Using multiple Java SDK versions on same machine - {Java} Streets
July 22, 2017 - If you open a new shell and run java -version, it should be global version which 1.8. We do use other command line utilities like Maven, Ant, gradle and many more. JEnv plugins will allow those command line utilties to recognize java version set by JEnv.
🌐
GitHub
github.com › jenv › jenv › issues › 422
JAVA_HOME not set properly when "system" is set to be global · Issue #422 · jenv/jenv
February 20, 2024 - > java --version openjdk 21.0.2 2024-01-16 LTS OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode) > /usr/libexec/java_home /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home > jenv --version jenv 0.5.6 > jenv doctor [OK] JAVA_HOME variable probably set by jenv PROMPT [OK] Java binaries in path are jenv shims [OK] Jenv is correctly loaded > jenv versions * system (set by /Users/sachen/.jenv/version) corretto64-1.8.0.342 oracle64-17.0.5 temurin64-11.0.17 > echo "${JAVA_HOME}" /Users/sachen/.jenv/versions/system > ls /Users/sachen/.jenv/versions/system "/Users/sachen/.jenv/versions/system": No such file or directory (os error 2)
Author   jenv