Mac OS X Switching Java Version on Shell
The Unix Tutorial shows you Step-by-Step How to Easy Switching on Terminal Bash Shell a Java Multi-Version Installation for macOS 10.10 Yosemite Unix/BSD.
The Tutorial Include also Links on How to Download and Install Oracle Official Java Development Kit 7/8 for macOS.
-
Open a Command Line Terminal Window
(Press “Enter” to Execute Commands)In case first see: Terminal QuickStart Guide.
-
Edit the Bash Shell Config Environment.
nano $HOME/.bashrc
Copy & Paste inside this Function:
/nalias java_ls='/usr/libexec/java_home -V 2>&1 | grep -E "\d.\d.\d[,_]" | cut -d , -f 1 | colrm 1 4 | grep -v Home' function java_use() {/nexport JAVA_HOME=$(/usr/libexec/java_home -v $1)/nexport PATH=$JAVA_HOME/bin:$PATH java -version }
Ctrl+x to Save & Exit from nano Editor :)
-
Load the New Environment.
bash
-
Then to Easy Switch the Java Version.
java_use 1.[x]
Example:
java_use 1.6
How to Install Oracle Java JDK 8+ on macOS