Saturday, July 2, 2016

Changing Your JDK on OS X

So you installed the newest and greatest JDK, maybe an early release. You have buyer's remorse, and want to go back to an older version of the JDK.

Good luck with that.

I'm joking!

First you need to know what versions of the JDK are currently on your OS X box. Check in the following directory.


That should have a list of your installed JDK's.

Alternatively, you can see your installed JDK's using the following command.

/usr/libexec/java_home -V

This list may include additional JDK's if you have a computer that's been around the block a few times.

Now, the real trick is running the one you want. If you just want to run a specific command using a specific JDK, then you might consider using the java_home tool.

Most developers of Java on OS X don't realize that they have a tool called java_home. It's not on the path by default. It is in the /usr/libexec directory. The java_home tool is very handy for issuing a command to run a Java app with the specified version of Java. For example, if you want to run javac with version 1.8.0_92 you could use the following command.

/usr/libexec/java_home -v 1.8.0_92 --exec javac -version

That would run the javac -version command with the 1.8.0_92 version of Java. The current default version of Java remains unchanged, so if you only need one app running with a different version of Java, the java_home command works great. Also note that running javac -version without the java_home command still runs javac under the default version of Java. So, you don't lose your default Java settings, just because you want to run one program with an older version of Java.

So if you want to change the default version of Java on OS X, where do you do that? That requires a bit of surgery with admin privileges. Also, you're going to need the installer for the JDK version you want as your default OS X JDK.

To change your default JDK, delete the following.

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin



I used these commands.

cd /Library/Internet Plug-Ins
sudo rm -rf JavaAppletPlugin.plugin
cd /Library/PreferencePanes
sudo rm JavaControlPanel.prefPane

Now run the JDK installer for the Java version you want as your default JDK.

You may find this only partially fixes your JDK version. The Java preferences panel may show your desired Java version, but running /usr/libexec/java_home still spits out the newer version of Java that you don't want as your default version.

If you're having this problem try exporting JAVA_HOME. You can do that permanently by adding the the following command to ~/.bash_profile substituting the version of Java you want for the 1.8 version I inserted in the command.

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

You may find that does great for the Terminal, but does nothing for helping Java based applications like Eclipse to run the correct version of Java. Isn't OS X great? *sigh*

In cases like that you might want to configure your applications to pick the right Java version. In Eclipse, for instance, you can browse into the app package and change the ini file to have a line like the following.


Now, suppose after you've gone through all this effort to make the older version of Java your default, you want to run a command or Java tool only run in a newer version of Java than the older one that you installed? Let's use jshell as an example. If you set your default OS X JDK to Java 8 and JShell is only in Java 9 and above, here's how to run it.

/usr/libexec/java_home -v 9 --exec jshell

There you have the easy ... yeah, right ... way to get a newer version of Java on your OS X box for development purposes, but use an older version for finicky programs like Eclipse that don't do well with change.


  1. Well, I get easy solution for all Java related problems at so I visit this site more often.

    1. I have read your blog its very attractive and impressive. I like it your blog.

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

  2. In the Java programming dialect, all source code is first composed in plain content records finishing with the .java expansion. Those source records are then assembled into .class documents by the javac compiler.
    web design lessons

  3. This information is impressive; I am inspired by your post writing style & how continuously you describe this topic. Java Training in Chennai

  4. Great post. I am actually getting ready to across this information, its very helpful for this blog. Also great with all of the valuable information you have keep up the good work you are doing well

    White Label Website Builder

  5. Java technology was created by James gosling, along with a small group of software engineers at Sun Microsystems in the early 90's. forum for programmers

  6. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts, have a nice weekend!

    Java Training in Bangalore

  7. And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
    java training in chennai

  8. I applaud the publication of your article on rearing Java. It's a good reminder to look on the Core Java Training & latest technologies such as Hadoop, Selenium, Android.

    Big Data Hadoop Training in Chennai

  9. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it... Java Training in Chennai | Blue prism Training in Chennai

  10. Awwsome informative blog ,Very good information thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us. Aviation Courses in Chennai | Best Aviation Academy in Chennai | Aviation Academy in Chennai | Aviation Training in Chennai | Aviation Institute in Chennai

  11. I am really enjoying reading your well written articles.
    It looks like you spend a lot of effort and time on your blog.
    I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..
    Java Training in Bangalore
    Best Java Training Institutes in Bangalore
    Java Course in Bangalore
    Java Training Institutes in Bangalore
    Java Institutes in Bangalore
    hadoop training in bangalore
    hadoop training in bangalore
    big data training in bangalore

  12. Come to BGAOC and play great games. good blackjack game Here you can play online casinos and earn large sums of money.

  13. Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.
    Modular Kitchen in Noida

  14. nice work keep it up thanks for sharing the knowledge.Thanks for sharing this type of information, it is so useful.
    Epoxy Grout manufacturer

  15. This comment has been removed by the author.

  16. We played with a guy in a toy on the phone, poker or something else and decided to add a bit of extras. We visited this site. steady online casino gambling sites We had a lot of fun and had an unforgettable time, plus we won a little for a romantic dinner

  17. Где можнокупить диодную ленту что бы хорошего качества и по нормальной цене, лучшее что я находил это в ekodio, отличная контора

  18. Thanks for your great and helpful presentation I like your good service. I always appreciate your post. That is very interesting I love reading and I am always searching for informative information like this.Also Checkout: angular 4 training in chennai | angularjs training in chennai | angularjs best training center in chennai | angularjs training in velachery

  19. I feel happy about and learning more about this topic. keep sharing your information regularly for my future reference. This content creates a new hope and inspiration with in me. Thanks for sharing article like this. the information which you have provided is better then other blog.
    Best IELTS Coaching institute in Dwarka

  20. This comment has been removed by the author.