Introduction to jEnv

Overview

This document provides basic understanding of jEnv and its important. We also go through each set to set up, and then use jenv to manage different JDK versions.

What is jEnv

  • This is command line tool to manage multiple different versions of JDK installations.
  • It basically sets JAVA_HOME inside our shell in a way that can be set globally, locally to the current working directory. We can update both ~/.bashrc or  ~/.zshrc profile to use jenv.
  • jEnv doesn’t install the Java JDK for us, rather helps us to manage multiple JDK installations
  • This is useful as we can switch between different Java versions. This is helpful when working with multiple applications having different Java versions.

Setting up jenv in MAC

  • brew install jenv
  • In case its throwing error, try below workaround, sometimes it might now allow to override /usr/local path
    sudo chmod +a “${USER} allow
    list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity” /usr/local/{bin,lib}
  • For Bash (we need to set jenv home, initialise jenv in our bash profile and then source our bash profile)
    1. echo ‘export PATH=”$HOME/.jenv/bin:$PATH”‘ >> ~/.bash_profile
    2. echo ‘eval “$(jenv init -)”‘ >> ~/.bash_profile
    3.  source ~/.bash_profile
  • Now lets do the same for (ZSH)
    1. echo ‘export PATH=”$HOME/.jenv/bin:$PATH”‘ >> ~/.zshrc
    2. echo ‘eval “$(jenv init -)”‘ >> ~/.zshrc
    3. source ~/.zshrc
  • Next step is to add JDK path name
    1. (adding JDK 1.8) : jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
    2. (adding jdk 17): jenv add /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
    3. Now check the if paths are added correctly
    4. Use command jenv versions
  • Next step is to set Java Home using jenv (recommended approach is to use local)
    1. to set JAVA Home locally in a directory use: jenv local 1.8
    2. setting globally: jenv global 1.8
    3. Above command can be used to set for 17.
  • Post this we need to set and enable maven and export plugin
    1. jenv enable-plugin maven  // enable maven 
    2. jenv enable-plugin export   // export
    3. jenv disable-plugin maven  // disable maven
    4. jenv disable-plugin export   // disable export
  • Post installation, use jenv –version to verify the version it has installed

Lets verify java version and maven

Troubleshooting tips

  • To verify of jenv is set correctly, use command : jenv doctor

  • if java home does not work or its not loaded by jenv, use below commands
    1. use jenv version to check if JDK paths are added , add the jre home again and source bash or zsh
    2. disable the plugin and maven
    3. enable both plugin and maven
    4. source bash/zsh profile again
  • If jenv is not loaded correctly , export the path and perform echo ‘eval “$(jenv init)”‘>>~/.zshrc
  • If using Intellij, use below steps to configure and verify

    1. You might need to change project structure setting to load correct JDK
    2. Check the SDK version in project and platform settings, click apply and press ok. You might need to restart intellij.

Leave a Reply