Installed Java 7 on Mac OS X but Terminal is still using version 6
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Upgrading to Java 7 on a Mac OS X and stepping into a world where the terminal stubbornly clings to Java 6 can be a perplexing issue, particularly for developers and professionals who rely on specific Java versions for various applications. This article walks through why this happens and how to resolve it by configuring the system properly.
Understanding the Problem
Mac OS X, like many operating systems, can have multiple versions of Java installed simultaneously. When Java 7 is installed, it does not necessarily mean that it becomes the default version used by the system or accessible from the terminal. This happens because the system's PATH variable and Java Home are still pointing to Java 6.
Key Concepts
- PATH Variable: This is an environment variable that specifies a set of directories where executable programs are located. In the case of Java, the terminal uses the first
javaexecutable found in these directories to execute Java programs. - JAVA_HOME: This environment variable points to the directory where the Java runtime environment (JRE) or Java development kit (JDK) is installed. This determines which Java version is used when running applications from third-party tools and servers.
Steps to Change Default Java Version
- Check Installed Java Versions: You can check which Java versions are currently installed by running:
This command will list all installed Java versions and their paths.
- Set JAVA_HOME for Java 7: Determine the installation path of Java 7 from the previous command output and set it as
JAVA_HOMEby adding the following line in your shell’s setup file (e.g.,.bashrc,.zshrc):
- Update PATH Variable: Ensure that the
PATHvariable is updated so it points to the new Java version. Modify the PATH variable by adding:
This sets the system to use the java executable from Java 7’s directory.
- Apply Changes: Apply the changes by sourcing the profile file:
- Verify the Update: Confirm that the terminal is using the correct version by checking:
This should now display Java 7 details.
Common Issues and Troubleshooting
If after following these steps, Java 7 is still not the default version, consider the following troubleshooting steps:
- Check for Typographical Errors: Ensure there are no typing errors in your configuration files.
- Conflict with Other Configuration Files: Sometimes, other configuration files like
.bash_profileor.profilemight override your settings. Check these files for any existing JAVA_HOME or PATH settings that could conflict.
Summary Table
| Issue | Possible Cause | Solution |
| Terminal uses Java 6 | PATH points to Java 6 | Update PATH to include Java 7 |
| JAVA_HOME points to Java 6 | Set JAVA_HOME to Java 7 path | |
| Changes not effective | Incorrect shell configuration file edited | Verify .bashrc, .bash_profile, .zshrc |
| Shell not reloaded after changes | Source the configuration file again |
Conclusion
Setting up Java on Mac OS X can sometimes be tricky, especially when managing multiple versions. By understanding how PATH and JAVA_HOME work and by configuring them correctly, you can ensure that the desired Java version is the default version for all your development needs.

