I just started to use jenv
, I followed a blog post that was explaining how to use jenv
and setup multiple java version on MacOSX. But the problem now I am running into is setting up the JAVA_HOME. As I switch java environment using jenv
I want to make sure JAVA_HOME
on my bash_profile also changes accordingly.
How do i do that?
I have following on my ~/.bash_profile
if which jenv > /dev/null; then eval "$(jenv init -)"; fi
Use jenv add to inform jenv where your Java environment is located. jenv does not, by itself, install Java. For example, on macOS, use brew to install the latest Java (OpenJDK 11) followed by the appropriate jenv add PATH_TO_JVM_HOME command to recognize it.
To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.
If your JDK installation didn't set JAVA_HOME automatically, you can always open the Windows environment variable editor and set it yourself. This is the easiest way to manually set JAVA_HOME in Windows 7, 8 and 10.
Try the "export" plugin:
jenv enable-plugin export
You can check the Export plugin section in Readme.md at the jEnv Github repo (https://github.com/gcuisinier/jenv)
For me, enabling the export
plugin like kimbaudi didn't work. Adding the following code to .bash_profile
(or .bashrc
, .zprofile
or .zshrc
depending on what shell you use) did the job for me:
if which jenv > /dev/null; then eval "$(jenv init -)"; fi
This was in the troubleshooting page, but they seemed to state it was in the instructions guide, which it wasn't.
You can add these alias in your ~/.bash_profile
file and easily switch between different JAVA versions.
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_11_HOME=$(/usr/libexec/java_home -v11)
alias java8='export JAVA_HOME=$JAVA_8_HOME'
alias java11='export JAVA_HOME=$JAVA_11_HOME’
To check the available java versions in your system use
jenv versions
jenv version
You can even set particular version for single project by using following command in private terminal.
jenv local 11.0
# Seconds option :-
Download adopt jdk from your choise from file -> project structure -> project sdk
and then add following function in your .zshrc to switch between different version as per requirement.
[Attaching screenshot for reference:] :-
Switch between different JDK versions
Add the below function in your ~/.bashrc or ~/.zshrc
jdk() {
version=$1
export JAVA_HOME=$(/usr/libexec/java_home -v"$version");
java -version
}
jdk 1.8 jdk 9 jdk 11 jdk 13
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With