> jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home We have two Java installed, so we run the command twice with their locations. To do this, we use the jenv command with add and specify the location of the JDK. We add the Java versions we want to the jenv list.
> echo 'export PATH="$HOME/.jenv/bin:$PATH"' > ~/.zshrc In our case, we use the zsh shell to use the below commands. To use the jenv tool, we need to set the variables with the command shell. Complete the installation by setting the variables to the shell.
We use the below command to install jenv on the local machine. Install the jenv tool using the Homebrew package management system.The jEnv is a command-line utility that makes the setup of environment variables easy. Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode) Java(TM) SE Runtime Environment (build 1.8.0_202-b08) We use the java -version command to check the current Java version, and when we execute it, the new version returns in the output. Check the Java version again to confirm that the version was changed.> export JAVA_HOME=`/usr/libexec/java_home -v 1.8` Note that backticks are being used around the path. We use the export command with the variable name next to it and then specify the location of usr/libexec/java_home with the argument -v and the version we want to change to 1.8.
JAVA_HOME is the variable that sets the system default for Java. Now we change the environment variable JAVA_HOME to a new value.
In this article, we will discuss how to change the version of Java installed on a mac machine. Use jenv to Change Java Version in MacOS.Use the Traditional Way to Change Java Version in MacOS.