Question
Why is Terminal on Mac OS X still using Java version 6 after installing JDK 7?
$ java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)
Answer
If you've installed JDK 7 on Mac OS X but your Terminal is still reporting the older version (Java 6), it’s often due to the environment variable settings in your shell configuration. This guide will help you troubleshoot the issue and set the correct Java version in your Terminal.
# To check and set JAVA_HOME variable
nano ~/.bash_profile
# Remove or comment the old JAVA_HOME line
# export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home"
# Set new JAVA_HOME for Java 7
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
Causes
- Java version settings in your shell profile (e.g., .bash_profile or .bashrc) might be overriding the default installation.
- The system might still point to the old Java version since the path hasn’t been updated after the new installation.
Solutions
- Check and modify your .bash_profile or .bashrc to point to the new Java version.
- Use the command `export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)` to set the correct JAVA_HOME variable automatically.
- Restart the Terminal or run `source ~/.bash_profile` to apply changes.
Common Mistakes
Mistake: Not saving changes in .bash_profile or .bashrc after editing.
Solution: Always ensure to save the document and restart the Terminal or run `source ~/.bash_profile`.
Mistake: Forgetting to update the JAVA_HOME variable after Java installation.
Solution: Use the command `export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)` for automatic configuration.
Helpers
- Java version in Terminal on Mac OS X
- change Java version Mac
- set JAVA_HOME Mac
- JDK installation issues Mac OS X
- Java version conflict Mac Terminal