Mac OS X and multiple Java versions












231















How can I install an additional java on MacOS? I installed jdk8 and that works fine. but now I need a jdk7 installation for development purposes. When trying to install the old version via DMG file, i get a warning, that there is already a newer version of java installed and the installer quits.



/usr/libexec/java_home -verbose
Matching Java Virtual Machines (1):
1.8.0_20, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home


How to install jdk7 in addition to this one?



Thanks

Dakky










share|improve this question





























    231















    How can I install an additional java on MacOS? I installed jdk8 and that works fine. but now I need a jdk7 installation for development purposes. When trying to install the old version via DMG file, i get a warning, that there is already a newer version of java installed and the installer quits.



    /usr/libexec/java_home -verbose
    Matching Java Virtual Machines (1):
    1.8.0_20, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home

    /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home


    How to install jdk7 in addition to this one?



    Thanks

    Dakky










    share|improve this question



























      231












      231








      231


      187






      How can I install an additional java on MacOS? I installed jdk8 and that works fine. but now I need a jdk7 installation for development purposes. When trying to install the old version via DMG file, i get a warning, that there is already a newer version of java installed and the installer quits.



      /usr/libexec/java_home -verbose
      Matching Java Virtual Machines (1):
      1.8.0_20, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home

      /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home


      How to install jdk7 in addition to this one?



      Thanks

      Dakky










      share|improve this question
















      How can I install an additional java on MacOS? I installed jdk8 and that works fine. but now I need a jdk7 installation for development purposes. When trying to install the old version via DMG file, i get a warning, that there is already a newer version of java installed and the installer quits.



      /usr/libexec/java_home -verbose
      Matching Java Virtual Machines (1):
      1.8.0_20, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home

      /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home


      How to install jdk7 in addition to this one?



      Thanks

      Dakky







      java macos install multiple-versions






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 11 '18 at 6:10







      user8389458

















      asked Oct 8 '14 at 8:41









      DakkarDakkar

      1,45541523




      1,45541523
























          9 Answers
          9






          active

          oldest

          votes


















          363














          The cleanest way to manage multiple java versions on Mac is to use Homebrew.



          And within Homebrew, use:





          • homebrew-cask to install the versions of java


          • jenv to manage the installed versions of java




          As seen on http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html , these are the steps to follow.




          1. install homebrew

          2. install homebrew jenv

          3. install homebrew-cask

          4. install a specific java version using cask (see "homebrew-cask versions" paragraph below)

          5. add this version for jenv to manage it

          6. check the version is correctly managed by jenv

          7. repeat steps 4 to 6 for each version of java you need




          homebrew-cask versions



          Add the homebrew/cask-versions tap to homebrew using:



          brew tap homebrew/cask-versions


          Then you can look at all the versions available:



          brew search java


          Then you can install the version(s) you like:



          brew cask install java7
          brew cask install java6


          And add them to be managed by jenv as usual.



          jenv add <javaVersionPathHere>


          I think this is the cleanest & simplest way to go about it.





          Another important thing to note, as mentioned in Mac OS X 10.6.7 Java Path Current JDK confusing :




          For different types of JDKs or installations, you will have different
          paths



          You can check the paths of the versions installed using /usr/libexec/java_home -V, see How do I check if the Java JDK is installed on Mac?



          On Mac OS X Mavericks, I found as following:



          1) Built-in JRE default: /Library/Internet
          Plug-Ins/JavaAppletPlugin.plugin/Contents/Home



          2) JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/



          3) JDKs downloaded from Oracle: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home






          Resources




          • Removing Java 8 JDK from Mac

          • http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html

          • http://sourabhbajaj.com/mac-setup/index.html

          • http://brew.sh

          • https://github.com/Homebrew/homebrew/tree/master/share/doc/homebrew#readme

          • http://sourabhbajaj.com/mac-setup/Homebrew/README.html

          • "brew tap” explained https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md

          • “brew versions” explained Homebrew install specific version of formula? and also https://github.com/Homebrew/homebrew-versions

          • https://github.com/caskroom/homebrew-cask

          • “cask versions”, similar to “brew versions”, see https://github.com/caskroom/homebrew-versions and also https://github.com/caskroom/homebrew-cask/issues/9447

          • http://www.jenv.be

          • https://github.com/gcuisinier/jenv






          share|improve this answer





















          • 14





            It would be good to mention that homebrew-cask can be installed with command brew install caskroom/cask/brew-cask instead of brew install cask which is an Emacs plugin.

            – Unnawut
            Sep 24 '15 at 20:14






          • 5





            I ran into a few problems while implementing this solution, one of which was with jenv returning the No such file or directory. error. This wiki helped solve it for me. github.com/gcuisinier/jenv/wiki/Trouble-Shooting

            – juil
            Aug 22 '16 at 20:41








          • 6





            I would add that all java installs would be in /Library/Java/JavaVirtualMachines/ and when adding them with jenv add you add path looking like this /Library/Java/JavaVirtualMachines/[specific-version]/Contents/Home/. Cheers!

            – Nikolay Tsenkov
            Oct 11 '16 at 9:28








          • 9





            As of Jun 23 2017, I run brew cask search java7 but got No Cask found for "java7".

            – Mingliang Liu
            Jun 24 '17 at 0:37






          • 2





            @MingliangLIU yeah me too... it really sucks. I found issues about this on Github were they mentioned some work arounds but I could not get it to work. So I ended up having to do it "the manual way" via apple and oracle's "Java versions download and install" web pages. Then using /usr/libexec/java_home -V to double check the paths where these were installed.

            – Adrien Be
            Jun 27 '17 at 16:44





















          231














          Uninstall jdk8, install jdk7, then reinstall jdk8.



          My approach to switching between them (in .profile) :



          export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
          export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
          export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

          alias java7='export JAVA_HOME=$JAVA_7_HOME'
          alias java8='export JAVA_HOME=$JAVA_8_HOME'
          alias java9='export JAVA_HOME=$JAVA_9_HOME'

          #default java8
          export JAVA_HOME=$JAVA_8_HOME


          Then you can simply type java7 or java8 in a terminal to switch versions.



          (edit: updated to add Dylans improvement for Java 9)






          share|improve this answer





















          • 17





            So far this is the best option for me. easily can switch to any version with just a simple command "java8" or "java7". Thanks for the help

            – M.M.H.Masud
            Aug 10 '15 at 17:08






          • 4





            Great ! :) And for other like me you can use : ls /Library/Java/JavaVirtualMachines to see which versions are available. Then you can switch on different 1.8.x versions. And also you have to add export PATH=$JAVA_HOME/bin:$PATH

            – Nico
            Mar 3 '16 at 16:44








          • 4





            Thanks for this one. I just wanted to mention that I've managed to do this by installing jdk7 after jdk8 (there is no need to uninstall jdk8).

            – Titus
            Jul 21 '16 at 10:36






          • 3





            Dunno why I wasted my time with jenv, as this just works, and does not clutter your shell startup by 0.5s with jenv init.

            – cvakiitho
            Aug 22 '17 at 13:14






          • 2





            If you are trying to get java 9 working in this fashion, the version argument to java_home for java 9 should simply be 9 e.g. export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

            – Dylan Nissley
            Oct 10 '17 at 10:27



















          72














          For macOS Sierra 420



          This guide was cobbled together from various sources (replies above as well as other posts), and works perfect.



          0. If you haven't already, install homebrew.



          See https://brew.sh/



          1. Install jenv



          brew install jenv


          2. Add jenv to the bash profile



          if which jenv > /dev/null; then eval "$(jenv init -)"; fi


          3. Add jenv to your path



          export PATH="$HOME/.jenv/shims:$PATH"


          4. Tap "caskroom/versions"



          FYI: "Tap" extends brew's list of available repos it can install, above and beyond brew's default list of available repos.



          brew tap caskroom/versions


          5. Install the latest version of java



          brew cask install java


          6. Install java 6 (or 7 or 8 whatever you need)



          brew cask install java6
          #brew cask install java7
          #brew cask install java8


          ? Maybe close and restart Terminal so it sees any new ENV vars that got setup.



          7. Review Installations



          All Java version get installed here: /Library/Java/JavaVirtualMachines lets take a look.



          ls -la /Library/Java/JavaVirtualMachines


          8. Add each path to jenv one-at-a-time.



          We need to add "/Contents/Home" to the version folder.
          WARNING: Use the actual paths on your machine... these are just EXAMPLE's



          jenv add /Library/Java/JavaVirtualMachines/1.6.0___EXAMPLE___/Contents/Home
          jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk___EXAMPLE___/Contents/Home


          9. Check if jenv registered OK



          jenv versions


          10. Set java version to use (globably)



          Where XX matches one of the items in the versions list above.



          jenv global XX


          Check java version



          java -version


          Check jenv versions



          Should also indicate the current version being used with an asterisk.



          jenv versions


          DONE





          Quick future reference



          To change java versions



          ... See the list of available java versions



          jenv versions


          ... then, where XX matches an item in the list above



          jenv global XX





          share|improve this answer


























          • Additionally, restart your terminal after brew cask install java*

            – squeeish
            Nov 22 '18 at 2:29











          • it works on Mojave too, thanks

            – Rizky Ariestiyansyah
            Mar 7 at 7:16











          • Clear and great explanation step by step.

            – Ritesh Singh
            Mar 12 at 16:37



















          32














          SDKMAN! is a great tool for using multiple versions of Java, Gradle, Groovy, Kotlin, and other JVM tools on Mac OS. Installation and usage doc are plainly on the main site.



          (I have no affiliation, just a happy user).



          As an example usage, if I type the following in a Terminal window, there is a list of available Java SDK versions (edited for brevity):



          $ sdk list java
          Available Java Versions
          + 9ea170
          > + 8u131
          7u141-zulu


          Here + denotes that the version is installed. > denotes which version is currently in use. To install a version:



          $ sdk install java 7u141-zulu


          To use a version in this Terminal window:



          $ sdk use java 9ea170





          share|improve this answer


























          • sdkman supports versions starting with java 1.7. If you're willing to use java 1.6 this solution may not be suitable for you.

            – Aykut Akıncı
            Mar 7 '18 at 10:56













          • sdkman is great, but they dont support specific releases within a version. For example Datastax Dev Center only works with 1.8.0_151 but I can't specify that with sdkman. Hopefully they add more versions.

            – Eduardo Dennis
            Jun 11 '18 at 14:43











          • If you have a local version, I think you can install it into SDKMan - sdkman.io/usage#localversion (but I haven't tried it)

            – Michael Easter
            Jun 11 '18 at 15:08



















          7














          As found on this website
          So Let’s begin by installing jEnv





          1. Run this in the terminal



            brew install https://raw.github.com/gcuisinier/jenv/homebrew/jenv.rb



          2. Add jEnv to the bash profile



            if which jenv > /dev/null; then eval "$(jenv init -)"; fi



          3. When you first install jEnv will not have any JDK associated with it.



            For example, I just installed JDK 8 but jEnv does not know about it. To check Java versions on jEnv



            At the moment it only found Java version(jre) on the system. The * shows the version currently selected. Unlike rvm and rbenv, jEnv cannot install JDK for you. You need to install JDK manually from Oracle website.



          4. Install JDK 6 from Apple website. This will install Java in /System/Library/Java/JavaVirtualMachines/. The reason we are installing Java 6 from Apple website is that SUN did not come up with JDK 6 for MAC, so Apple created/modified its own deployment version.


          5. Similarly install JDK7 and JDK8.



          6. Add JDKs to jEnv.



            JDK 6:



            JDK 7:
            http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518ab9bc47d4.png



            JDK 8:
            http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abb2c1217.png




          7. Check the java versions installed using jenv



            http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abceb0deb.png




          8. So now we have 3 versions of Java on our system. To set a default version use the command



            jenv local <jenv version>


            Ex – I wanted Jdk 1.6 to start IntelliJ



            jenv local oracle64-1.6.0.65



          9. check the java version



            java -version
            http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abe376dd0.png




          That’s it. We now have multiple versions of java and we can switch between them easily. jEnv also has some other features, such as wrappers for Gradle, Ant, Maven, etc, and the ability to set JVM options globally or locally. Check out the documentation for more information.






          share|improve this answer





















          • 3





            Do not put images of your commands, it makes difficult to copy/paste them. To highlight commands, use the backticks "`" for a single word or a short command, or indent your command with 4 spaces on its own line (or multiples of 4 in lists).

            – Seki
            Aug 5 '16 at 10:48






          • 1





            Thanks Seki. I was struggling to post images and spent a long time trying to format but could not get it right. Thanks for sharing the backticks info.

            – Dinesh Arora
            Aug 5 '16 at 17:20






          • 3





            I think you may have used the same image four times.

            – Ellen Spertus
            May 18 '18 at 20:00



















          5














          I find this Java version manager called Jabba recently and the usage is very similar to version managers of other languages like rvm(ruby), nvm(node), pyenv(python), etc. Also it's cross platform so definitely it can be used on Mac.



          After installation, it will create a dir in ~/.jabba to put all the Java versions you install. It "Supports installation of Oracle JDK (default) / Server JRE, Zulu OpenJDK (since 0.3.0), IBM SDK, Java Technology Edition (since 0.6.0) and from custom URLs.".



          Basic usage is listed on their Github. A quick summary to start:



          curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh

          # install Oracle JDK
          jabba install 1.8 # "jabba use 1.8" will be called automatically
          jabba install 1.7 # "jabba use 1.7" will be called automatically

          # list all installed JDK's
          jabba ls

          # switch to a different version of JDK
          jabba use 1.8





          share|improve this answer































            4














            I am using Mac OS X 10.9.5. This is how I manage multiple JDK/JRE on my machine when I need one version to run application A and use another version for application B.



            I created the following script after getting some help online.



            #!bin/sh
            function setjdk() {
            if [ $# -ne 0 ]; then
            removeFromPath '/Library/Java/JavaVirtualMachines/'
            if [ -n "${JAVA_HOME+x}" ]; then
            removeFromPath $JAVA_HOME
            fi
            export JAVA_HOME=/Library/Java/JavaVirtualMachines/$1/Contents/Home
            export PATH=$JAVA_HOME/bin:$PATH
            fi
            }
            function removeFromPath() {
            export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
            }
            #setjdk jdk1.8.0_60.jdk
            setjdk jdk1.7.0_15.jdk


            I put the above script in .profile file. Just open terminal, type vi .profile, append the script with the above snippet and save it. Once your out type source .profile, this will run your profile script without you having to restart the terminal. Now type java -version it should show 1.7 as your current version. If you intend to change it to 1.8 then comment the line setjdk jdk1.7.0_15.jdk and uncomment the line setjdk jdk1.8.0_60.jdk. Save the script and run it again with source command. I use this mechanism to manage multiple versions of JDK/JRE when I have to compile 2 different Maven projects which need different java versions.






            share|improve this answer































              3














              Jenv on Mac Sierra:



              if not working after install, do this bug fix to add java executable to path



              export PATH="$HOME/.jenv/shims:$PATH"


              even though eval "$(jenv init -)" could do this job. The reason is /bin folder is not there anymore as describe in it's homepage, but shim folder is used as /bin instead.




              • Make sure ~/.jenv is there


              • which java may print /Library/...

              • jenv global 1.8

              • jenv shell 1.8


              Eventually, which java gives you:




              /Users/xxxx/.jenv/shims/java







              share|improve this answer































                0














                Here's a more DRY version for bash (Based on Vegard's answer)



                Replace 1.7 and 1.8 with whatever versions you are interested with
                and you'll get an alias called 'javaX'; where 'X' is the java version (7 / 8 in the snippet below) that will allow you to easily switch versions



                for version in 1.7 1.8; do
                v="${version: -1}"
                h=JAVA_"$v"_HOME

                export "$h"=$(/usr/libexec/java_home -v $version)

                alias "java$v"="export JAVA_HOME=$$h"
                done





                share|improve this answer























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26252591%2fmac-os-x-and-multiple-java-versions%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  9 Answers
                  9






                  active

                  oldest

                  votes








                  9 Answers
                  9






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  363














                  The cleanest way to manage multiple java versions on Mac is to use Homebrew.



                  And within Homebrew, use:





                  • homebrew-cask to install the versions of java


                  • jenv to manage the installed versions of java




                  As seen on http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html , these are the steps to follow.




                  1. install homebrew

                  2. install homebrew jenv

                  3. install homebrew-cask

                  4. install a specific java version using cask (see "homebrew-cask versions" paragraph below)

                  5. add this version for jenv to manage it

                  6. check the version is correctly managed by jenv

                  7. repeat steps 4 to 6 for each version of java you need




                  homebrew-cask versions



                  Add the homebrew/cask-versions tap to homebrew using:



                  brew tap homebrew/cask-versions


                  Then you can look at all the versions available:



                  brew search java


                  Then you can install the version(s) you like:



                  brew cask install java7
                  brew cask install java6


                  And add them to be managed by jenv as usual.



                  jenv add <javaVersionPathHere>


                  I think this is the cleanest & simplest way to go about it.





                  Another important thing to note, as mentioned in Mac OS X 10.6.7 Java Path Current JDK confusing :




                  For different types of JDKs or installations, you will have different
                  paths



                  You can check the paths of the versions installed using /usr/libexec/java_home -V, see How do I check if the Java JDK is installed on Mac?



                  On Mac OS X Mavericks, I found as following:



                  1) Built-in JRE default: /Library/Internet
                  Plug-Ins/JavaAppletPlugin.plugin/Contents/Home



                  2) JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/



                  3) JDKs downloaded from Oracle: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home






                  Resources




                  • Removing Java 8 JDK from Mac

                  • http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html

                  • http://sourabhbajaj.com/mac-setup/index.html

                  • http://brew.sh

                  • https://github.com/Homebrew/homebrew/tree/master/share/doc/homebrew#readme

                  • http://sourabhbajaj.com/mac-setup/Homebrew/README.html

                  • "brew tap” explained https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md

                  • “brew versions” explained Homebrew install specific version of formula? and also https://github.com/Homebrew/homebrew-versions

                  • https://github.com/caskroom/homebrew-cask

                  • “cask versions”, similar to “brew versions”, see https://github.com/caskroom/homebrew-versions and also https://github.com/caskroom/homebrew-cask/issues/9447

                  • http://www.jenv.be

                  • https://github.com/gcuisinier/jenv






                  share|improve this answer





















                  • 14





                    It would be good to mention that homebrew-cask can be installed with command brew install caskroom/cask/brew-cask instead of brew install cask which is an Emacs plugin.

                    – Unnawut
                    Sep 24 '15 at 20:14






                  • 5





                    I ran into a few problems while implementing this solution, one of which was with jenv returning the No such file or directory. error. This wiki helped solve it for me. github.com/gcuisinier/jenv/wiki/Trouble-Shooting

                    – juil
                    Aug 22 '16 at 20:41








                  • 6





                    I would add that all java installs would be in /Library/Java/JavaVirtualMachines/ and when adding them with jenv add you add path looking like this /Library/Java/JavaVirtualMachines/[specific-version]/Contents/Home/. Cheers!

                    – Nikolay Tsenkov
                    Oct 11 '16 at 9:28








                  • 9





                    As of Jun 23 2017, I run brew cask search java7 but got No Cask found for "java7".

                    – Mingliang Liu
                    Jun 24 '17 at 0:37






                  • 2





                    @MingliangLIU yeah me too... it really sucks. I found issues about this on Github were they mentioned some work arounds but I could not get it to work. So I ended up having to do it "the manual way" via apple and oracle's "Java versions download and install" web pages. Then using /usr/libexec/java_home -V to double check the paths where these were installed.

                    – Adrien Be
                    Jun 27 '17 at 16:44


















                  363














                  The cleanest way to manage multiple java versions on Mac is to use Homebrew.



                  And within Homebrew, use:





                  • homebrew-cask to install the versions of java


                  • jenv to manage the installed versions of java




                  As seen on http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html , these are the steps to follow.




                  1. install homebrew

                  2. install homebrew jenv

                  3. install homebrew-cask

                  4. install a specific java version using cask (see "homebrew-cask versions" paragraph below)

                  5. add this version for jenv to manage it

                  6. check the version is correctly managed by jenv

                  7. repeat steps 4 to 6 for each version of java you need




                  homebrew-cask versions



                  Add the homebrew/cask-versions tap to homebrew using:



                  brew tap homebrew/cask-versions


                  Then you can look at all the versions available:



                  brew search java


                  Then you can install the version(s) you like:



                  brew cask install java7
                  brew cask install java6


                  And add them to be managed by jenv as usual.



                  jenv add <javaVersionPathHere>


                  I think this is the cleanest & simplest way to go about it.





                  Another important thing to note, as mentioned in Mac OS X 10.6.7 Java Path Current JDK confusing :




                  For different types of JDKs or installations, you will have different
                  paths



                  You can check the paths of the versions installed using /usr/libexec/java_home -V, see How do I check if the Java JDK is installed on Mac?



                  On Mac OS X Mavericks, I found as following:



                  1) Built-in JRE default: /Library/Internet
                  Plug-Ins/JavaAppletPlugin.plugin/Contents/Home



                  2) JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/



                  3) JDKs downloaded from Oracle: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home






                  Resources




                  • Removing Java 8 JDK from Mac

                  • http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html

                  • http://sourabhbajaj.com/mac-setup/index.html

                  • http://brew.sh

                  • https://github.com/Homebrew/homebrew/tree/master/share/doc/homebrew#readme

                  • http://sourabhbajaj.com/mac-setup/Homebrew/README.html

                  • "brew tap” explained https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md

                  • “brew versions” explained Homebrew install specific version of formula? and also https://github.com/Homebrew/homebrew-versions

                  • https://github.com/caskroom/homebrew-cask

                  • “cask versions”, similar to “brew versions”, see https://github.com/caskroom/homebrew-versions and also https://github.com/caskroom/homebrew-cask/issues/9447

                  • http://www.jenv.be

                  • https://github.com/gcuisinier/jenv






                  share|improve this answer





















                  • 14





                    It would be good to mention that homebrew-cask can be installed with command brew install caskroom/cask/brew-cask instead of brew install cask which is an Emacs plugin.

                    – Unnawut
                    Sep 24 '15 at 20:14






                  • 5





                    I ran into a few problems while implementing this solution, one of which was with jenv returning the No such file or directory. error. This wiki helped solve it for me. github.com/gcuisinier/jenv/wiki/Trouble-Shooting

                    – juil
                    Aug 22 '16 at 20:41








                  • 6





                    I would add that all java installs would be in /Library/Java/JavaVirtualMachines/ and when adding them with jenv add you add path looking like this /Library/Java/JavaVirtualMachines/[specific-version]/Contents/Home/. Cheers!

                    – Nikolay Tsenkov
                    Oct 11 '16 at 9:28








                  • 9





                    As of Jun 23 2017, I run brew cask search java7 but got No Cask found for "java7".

                    – Mingliang Liu
                    Jun 24 '17 at 0:37






                  • 2





                    @MingliangLIU yeah me too... it really sucks. I found issues about this on Github were they mentioned some work arounds but I could not get it to work. So I ended up having to do it "the manual way" via apple and oracle's "Java versions download and install" web pages. Then using /usr/libexec/java_home -V to double check the paths where these were installed.

                    – Adrien Be
                    Jun 27 '17 at 16:44
















                  363












                  363








                  363







                  The cleanest way to manage multiple java versions on Mac is to use Homebrew.



                  And within Homebrew, use:





                  • homebrew-cask to install the versions of java


                  • jenv to manage the installed versions of java




                  As seen on http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html , these are the steps to follow.




                  1. install homebrew

                  2. install homebrew jenv

                  3. install homebrew-cask

                  4. install a specific java version using cask (see "homebrew-cask versions" paragraph below)

                  5. add this version for jenv to manage it

                  6. check the version is correctly managed by jenv

                  7. repeat steps 4 to 6 for each version of java you need




                  homebrew-cask versions



                  Add the homebrew/cask-versions tap to homebrew using:



                  brew tap homebrew/cask-versions


                  Then you can look at all the versions available:



                  brew search java


                  Then you can install the version(s) you like:



                  brew cask install java7
                  brew cask install java6


                  And add them to be managed by jenv as usual.



                  jenv add <javaVersionPathHere>


                  I think this is the cleanest & simplest way to go about it.





                  Another important thing to note, as mentioned in Mac OS X 10.6.7 Java Path Current JDK confusing :




                  For different types of JDKs or installations, you will have different
                  paths



                  You can check the paths of the versions installed using /usr/libexec/java_home -V, see How do I check if the Java JDK is installed on Mac?



                  On Mac OS X Mavericks, I found as following:



                  1) Built-in JRE default: /Library/Internet
                  Plug-Ins/JavaAppletPlugin.plugin/Contents/Home



                  2) JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/



                  3) JDKs downloaded from Oracle: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home






                  Resources




                  • Removing Java 8 JDK from Mac

                  • http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html

                  • http://sourabhbajaj.com/mac-setup/index.html

                  • http://brew.sh

                  • https://github.com/Homebrew/homebrew/tree/master/share/doc/homebrew#readme

                  • http://sourabhbajaj.com/mac-setup/Homebrew/README.html

                  • "brew tap” explained https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md

                  • “brew versions” explained Homebrew install specific version of formula? and also https://github.com/Homebrew/homebrew-versions

                  • https://github.com/caskroom/homebrew-cask

                  • “cask versions”, similar to “brew versions”, see https://github.com/caskroom/homebrew-versions and also https://github.com/caskroom/homebrew-cask/issues/9447

                  • http://www.jenv.be

                  • https://github.com/gcuisinier/jenv






                  share|improve this answer















                  The cleanest way to manage multiple java versions on Mac is to use Homebrew.



                  And within Homebrew, use:





                  • homebrew-cask to install the versions of java


                  • jenv to manage the installed versions of java




                  As seen on http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html , these are the steps to follow.




                  1. install homebrew

                  2. install homebrew jenv

                  3. install homebrew-cask

                  4. install a specific java version using cask (see "homebrew-cask versions" paragraph below)

                  5. add this version for jenv to manage it

                  6. check the version is correctly managed by jenv

                  7. repeat steps 4 to 6 for each version of java you need




                  homebrew-cask versions



                  Add the homebrew/cask-versions tap to homebrew using:



                  brew tap homebrew/cask-versions


                  Then you can look at all the versions available:



                  brew search java


                  Then you can install the version(s) you like:



                  brew cask install java7
                  brew cask install java6


                  And add them to be managed by jenv as usual.



                  jenv add <javaVersionPathHere>


                  I think this is the cleanest & simplest way to go about it.





                  Another important thing to note, as mentioned in Mac OS X 10.6.7 Java Path Current JDK confusing :




                  For different types of JDKs or installations, you will have different
                  paths



                  You can check the paths of the versions installed using /usr/libexec/java_home -V, see How do I check if the Java JDK is installed on Mac?



                  On Mac OS X Mavericks, I found as following:



                  1) Built-in JRE default: /Library/Internet
                  Plug-Ins/JavaAppletPlugin.plugin/Contents/Home



                  2) JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/



                  3) JDKs downloaded from Oracle: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home






                  Resources




                  • Removing Java 8 JDK from Mac

                  • http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html

                  • http://sourabhbajaj.com/mac-setup/index.html

                  • http://brew.sh

                  • https://github.com/Homebrew/homebrew/tree/master/share/doc/homebrew#readme

                  • http://sourabhbajaj.com/mac-setup/Homebrew/README.html

                  • "brew tap” explained https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md

                  • “brew versions” explained Homebrew install specific version of formula? and also https://github.com/Homebrew/homebrew-versions

                  • https://github.com/caskroom/homebrew-cask

                  • “cask versions”, similar to “brew versions”, see https://github.com/caskroom/homebrew-versions and also https://github.com/caskroom/homebrew-cask/issues/9447

                  • http://www.jenv.be

                  • https://github.com/gcuisinier/jenv







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 22 '18 at 6:10









                  Interlated

                  1,37512138




                  1,37512138










                  answered Mar 22 '15 at 14:53









                  Adrien BeAdrien Be

                  12.8k1272123




                  12.8k1272123








                  • 14





                    It would be good to mention that homebrew-cask can be installed with command brew install caskroom/cask/brew-cask instead of brew install cask which is an Emacs plugin.

                    – Unnawut
                    Sep 24 '15 at 20:14






                  • 5





                    I ran into a few problems while implementing this solution, one of which was with jenv returning the No such file or directory. error. This wiki helped solve it for me. github.com/gcuisinier/jenv/wiki/Trouble-Shooting

                    – juil
                    Aug 22 '16 at 20:41








                  • 6





                    I would add that all java installs would be in /Library/Java/JavaVirtualMachines/ and when adding them with jenv add you add path looking like this /Library/Java/JavaVirtualMachines/[specific-version]/Contents/Home/. Cheers!

                    – Nikolay Tsenkov
                    Oct 11 '16 at 9:28








                  • 9





                    As of Jun 23 2017, I run brew cask search java7 but got No Cask found for "java7".

                    – Mingliang Liu
                    Jun 24 '17 at 0:37






                  • 2





                    @MingliangLIU yeah me too... it really sucks. I found issues about this on Github were they mentioned some work arounds but I could not get it to work. So I ended up having to do it "the manual way" via apple and oracle's "Java versions download and install" web pages. Then using /usr/libexec/java_home -V to double check the paths where these were installed.

                    – Adrien Be
                    Jun 27 '17 at 16:44
















                  • 14





                    It would be good to mention that homebrew-cask can be installed with command brew install caskroom/cask/brew-cask instead of brew install cask which is an Emacs plugin.

                    – Unnawut
                    Sep 24 '15 at 20:14






                  • 5





                    I ran into a few problems while implementing this solution, one of which was with jenv returning the No such file or directory. error. This wiki helped solve it for me. github.com/gcuisinier/jenv/wiki/Trouble-Shooting

                    – juil
                    Aug 22 '16 at 20:41








                  • 6





                    I would add that all java installs would be in /Library/Java/JavaVirtualMachines/ and when adding them with jenv add you add path looking like this /Library/Java/JavaVirtualMachines/[specific-version]/Contents/Home/. Cheers!

                    – Nikolay Tsenkov
                    Oct 11 '16 at 9:28








                  • 9





                    As of Jun 23 2017, I run brew cask search java7 but got No Cask found for "java7".

                    – Mingliang Liu
                    Jun 24 '17 at 0:37






                  • 2





                    @MingliangLIU yeah me too... it really sucks. I found issues about this on Github were they mentioned some work arounds but I could not get it to work. So I ended up having to do it "the manual way" via apple and oracle's "Java versions download and install" web pages. Then using /usr/libexec/java_home -V to double check the paths where these were installed.

                    – Adrien Be
                    Jun 27 '17 at 16:44










                  14




                  14





                  It would be good to mention that homebrew-cask can be installed with command brew install caskroom/cask/brew-cask instead of brew install cask which is an Emacs plugin.

                  – Unnawut
                  Sep 24 '15 at 20:14





                  It would be good to mention that homebrew-cask can be installed with command brew install caskroom/cask/brew-cask instead of brew install cask which is an Emacs plugin.

                  – Unnawut
                  Sep 24 '15 at 20:14




                  5




                  5





                  I ran into a few problems while implementing this solution, one of which was with jenv returning the No such file or directory. error. This wiki helped solve it for me. github.com/gcuisinier/jenv/wiki/Trouble-Shooting

                  – juil
                  Aug 22 '16 at 20:41







                  I ran into a few problems while implementing this solution, one of which was with jenv returning the No such file or directory. error. This wiki helped solve it for me. github.com/gcuisinier/jenv/wiki/Trouble-Shooting

                  – juil
                  Aug 22 '16 at 20:41






                  6




                  6





                  I would add that all java installs would be in /Library/Java/JavaVirtualMachines/ and when adding them with jenv add you add path looking like this /Library/Java/JavaVirtualMachines/[specific-version]/Contents/Home/. Cheers!

                  – Nikolay Tsenkov
                  Oct 11 '16 at 9:28







                  I would add that all java installs would be in /Library/Java/JavaVirtualMachines/ and when adding them with jenv add you add path looking like this /Library/Java/JavaVirtualMachines/[specific-version]/Contents/Home/. Cheers!

                  – Nikolay Tsenkov
                  Oct 11 '16 at 9:28






                  9




                  9





                  As of Jun 23 2017, I run brew cask search java7 but got No Cask found for "java7".

                  – Mingliang Liu
                  Jun 24 '17 at 0:37





                  As of Jun 23 2017, I run brew cask search java7 but got No Cask found for "java7".

                  – Mingliang Liu
                  Jun 24 '17 at 0:37




                  2




                  2





                  @MingliangLIU yeah me too... it really sucks. I found issues about this on Github were they mentioned some work arounds but I could not get it to work. So I ended up having to do it "the manual way" via apple and oracle's "Java versions download and install" web pages. Then using /usr/libexec/java_home -V to double check the paths where these were installed.

                  – Adrien Be
                  Jun 27 '17 at 16:44







                  @MingliangLIU yeah me too... it really sucks. I found issues about this on Github were they mentioned some work arounds but I could not get it to work. So I ended up having to do it "the manual way" via apple and oracle's "Java versions download and install" web pages. Then using /usr/libexec/java_home -V to double check the paths where these were installed.

                  – Adrien Be
                  Jun 27 '17 at 16:44















                  231














                  Uninstall jdk8, install jdk7, then reinstall jdk8.



                  My approach to switching between them (in .profile) :



                  export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
                  export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
                  export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                  alias java7='export JAVA_HOME=$JAVA_7_HOME'
                  alias java8='export JAVA_HOME=$JAVA_8_HOME'
                  alias java9='export JAVA_HOME=$JAVA_9_HOME'

                  #default java8
                  export JAVA_HOME=$JAVA_8_HOME


                  Then you can simply type java7 or java8 in a terminal to switch versions.



                  (edit: updated to add Dylans improvement for Java 9)






                  share|improve this answer





















                  • 17





                    So far this is the best option for me. easily can switch to any version with just a simple command "java8" or "java7". Thanks for the help

                    – M.M.H.Masud
                    Aug 10 '15 at 17:08






                  • 4





                    Great ! :) And for other like me you can use : ls /Library/Java/JavaVirtualMachines to see which versions are available. Then you can switch on different 1.8.x versions. And also you have to add export PATH=$JAVA_HOME/bin:$PATH

                    – Nico
                    Mar 3 '16 at 16:44








                  • 4





                    Thanks for this one. I just wanted to mention that I've managed to do this by installing jdk7 after jdk8 (there is no need to uninstall jdk8).

                    – Titus
                    Jul 21 '16 at 10:36






                  • 3





                    Dunno why I wasted my time with jenv, as this just works, and does not clutter your shell startup by 0.5s with jenv init.

                    – cvakiitho
                    Aug 22 '17 at 13:14






                  • 2





                    If you are trying to get java 9 working in this fashion, the version argument to java_home for java 9 should simply be 9 e.g. export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                    – Dylan Nissley
                    Oct 10 '17 at 10:27
















                  231














                  Uninstall jdk8, install jdk7, then reinstall jdk8.



                  My approach to switching between them (in .profile) :



                  export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
                  export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
                  export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                  alias java7='export JAVA_HOME=$JAVA_7_HOME'
                  alias java8='export JAVA_HOME=$JAVA_8_HOME'
                  alias java9='export JAVA_HOME=$JAVA_9_HOME'

                  #default java8
                  export JAVA_HOME=$JAVA_8_HOME


                  Then you can simply type java7 or java8 in a terminal to switch versions.



                  (edit: updated to add Dylans improvement for Java 9)






                  share|improve this answer





















                  • 17





                    So far this is the best option for me. easily can switch to any version with just a simple command "java8" or "java7". Thanks for the help

                    – M.M.H.Masud
                    Aug 10 '15 at 17:08






                  • 4





                    Great ! :) And for other like me you can use : ls /Library/Java/JavaVirtualMachines to see which versions are available. Then you can switch on different 1.8.x versions. And also you have to add export PATH=$JAVA_HOME/bin:$PATH

                    – Nico
                    Mar 3 '16 at 16:44








                  • 4





                    Thanks for this one. I just wanted to mention that I've managed to do this by installing jdk7 after jdk8 (there is no need to uninstall jdk8).

                    – Titus
                    Jul 21 '16 at 10:36






                  • 3





                    Dunno why I wasted my time with jenv, as this just works, and does not clutter your shell startup by 0.5s with jenv init.

                    – cvakiitho
                    Aug 22 '17 at 13:14






                  • 2





                    If you are trying to get java 9 working in this fashion, the version argument to java_home for java 9 should simply be 9 e.g. export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                    – Dylan Nissley
                    Oct 10 '17 at 10:27














                  231












                  231








                  231







                  Uninstall jdk8, install jdk7, then reinstall jdk8.



                  My approach to switching between them (in .profile) :



                  export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
                  export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
                  export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                  alias java7='export JAVA_HOME=$JAVA_7_HOME'
                  alias java8='export JAVA_HOME=$JAVA_8_HOME'
                  alias java9='export JAVA_HOME=$JAVA_9_HOME'

                  #default java8
                  export JAVA_HOME=$JAVA_8_HOME


                  Then you can simply type java7 or java8 in a terminal to switch versions.



                  (edit: updated to add Dylans improvement for Java 9)






                  share|improve this answer















                  Uninstall jdk8, install jdk7, then reinstall jdk8.



                  My approach to switching between them (in .profile) :



                  export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
                  export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
                  export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                  alias java7='export JAVA_HOME=$JAVA_7_HOME'
                  alias java8='export JAVA_HOME=$JAVA_8_HOME'
                  alias java9='export JAVA_HOME=$JAVA_9_HOME'

                  #default java8
                  export JAVA_HOME=$JAVA_8_HOME


                  Then you can simply type java7 or java8 in a terminal to switch versions.



                  (edit: updated to add Dylans improvement for Java 9)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Oct 10 '17 at 13:32

























                  answered Oct 8 '14 at 9:02









                  VegardVegard

                  2,92211223




                  2,92211223








                  • 17





                    So far this is the best option for me. easily can switch to any version with just a simple command "java8" or "java7". Thanks for the help

                    – M.M.H.Masud
                    Aug 10 '15 at 17:08






                  • 4





                    Great ! :) And for other like me you can use : ls /Library/Java/JavaVirtualMachines to see which versions are available. Then you can switch on different 1.8.x versions. And also you have to add export PATH=$JAVA_HOME/bin:$PATH

                    – Nico
                    Mar 3 '16 at 16:44








                  • 4





                    Thanks for this one. I just wanted to mention that I've managed to do this by installing jdk7 after jdk8 (there is no need to uninstall jdk8).

                    – Titus
                    Jul 21 '16 at 10:36






                  • 3





                    Dunno why I wasted my time with jenv, as this just works, and does not clutter your shell startup by 0.5s with jenv init.

                    – cvakiitho
                    Aug 22 '17 at 13:14






                  • 2





                    If you are trying to get java 9 working in this fashion, the version argument to java_home for java 9 should simply be 9 e.g. export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                    – Dylan Nissley
                    Oct 10 '17 at 10:27














                  • 17





                    So far this is the best option for me. easily can switch to any version with just a simple command "java8" or "java7". Thanks for the help

                    – M.M.H.Masud
                    Aug 10 '15 at 17:08






                  • 4





                    Great ! :) And for other like me you can use : ls /Library/Java/JavaVirtualMachines to see which versions are available. Then you can switch on different 1.8.x versions. And also you have to add export PATH=$JAVA_HOME/bin:$PATH

                    – Nico
                    Mar 3 '16 at 16:44








                  • 4





                    Thanks for this one. I just wanted to mention that I've managed to do this by installing jdk7 after jdk8 (there is no need to uninstall jdk8).

                    – Titus
                    Jul 21 '16 at 10:36






                  • 3





                    Dunno why I wasted my time with jenv, as this just works, and does not clutter your shell startup by 0.5s with jenv init.

                    – cvakiitho
                    Aug 22 '17 at 13:14






                  • 2





                    If you are trying to get java 9 working in this fashion, the version argument to java_home for java 9 should simply be 9 e.g. export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                    – Dylan Nissley
                    Oct 10 '17 at 10:27








                  17




                  17





                  So far this is the best option for me. easily can switch to any version with just a simple command "java8" or "java7". Thanks for the help

                  – M.M.H.Masud
                  Aug 10 '15 at 17:08





                  So far this is the best option for me. easily can switch to any version with just a simple command "java8" or "java7". Thanks for the help

                  – M.M.H.Masud
                  Aug 10 '15 at 17:08




                  4




                  4





                  Great ! :) And for other like me you can use : ls /Library/Java/JavaVirtualMachines to see which versions are available. Then you can switch on different 1.8.x versions. And also you have to add export PATH=$JAVA_HOME/bin:$PATH

                  – Nico
                  Mar 3 '16 at 16:44







                  Great ! :) And for other like me you can use : ls /Library/Java/JavaVirtualMachines to see which versions are available. Then you can switch on different 1.8.x versions. And also you have to add export PATH=$JAVA_HOME/bin:$PATH

                  – Nico
                  Mar 3 '16 at 16:44






                  4




                  4





                  Thanks for this one. I just wanted to mention that I've managed to do this by installing jdk7 after jdk8 (there is no need to uninstall jdk8).

                  – Titus
                  Jul 21 '16 at 10:36





                  Thanks for this one. I just wanted to mention that I've managed to do this by installing jdk7 after jdk8 (there is no need to uninstall jdk8).

                  – Titus
                  Jul 21 '16 at 10:36




                  3




                  3





                  Dunno why I wasted my time with jenv, as this just works, and does not clutter your shell startup by 0.5s with jenv init.

                  – cvakiitho
                  Aug 22 '17 at 13:14





                  Dunno why I wasted my time with jenv, as this just works, and does not clutter your shell startup by 0.5s with jenv init.

                  – cvakiitho
                  Aug 22 '17 at 13:14




                  2




                  2





                  If you are trying to get java 9 working in this fashion, the version argument to java_home for java 9 should simply be 9 e.g. export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                  – Dylan Nissley
                  Oct 10 '17 at 10:27





                  If you are trying to get java 9 working in this fashion, the version argument to java_home for java 9 should simply be 9 e.g. export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

                  – Dylan Nissley
                  Oct 10 '17 at 10:27











                  72














                  For macOS Sierra 420



                  This guide was cobbled together from various sources (replies above as well as other posts), and works perfect.



                  0. If you haven't already, install homebrew.



                  See https://brew.sh/



                  1. Install jenv



                  brew install jenv


                  2. Add jenv to the bash profile



                  if which jenv > /dev/null; then eval "$(jenv init -)"; fi


                  3. Add jenv to your path



                  export PATH="$HOME/.jenv/shims:$PATH"


                  4. Tap "caskroom/versions"



                  FYI: "Tap" extends brew's list of available repos it can install, above and beyond brew's default list of available repos.



                  brew tap caskroom/versions


                  5. Install the latest version of java



                  brew cask install java


                  6. Install java 6 (or 7 or 8 whatever you need)



                  brew cask install java6
                  #brew cask install java7
                  #brew cask install java8


                  ? Maybe close and restart Terminal so it sees any new ENV vars that got setup.



                  7. Review Installations



                  All Java version get installed here: /Library/Java/JavaVirtualMachines lets take a look.



                  ls -la /Library/Java/JavaVirtualMachines


                  8. Add each path to jenv one-at-a-time.



                  We need to add "/Contents/Home" to the version folder.
                  WARNING: Use the actual paths on your machine... these are just EXAMPLE's



                  jenv add /Library/Java/JavaVirtualMachines/1.6.0___EXAMPLE___/Contents/Home
                  jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk___EXAMPLE___/Contents/Home


                  9. Check if jenv registered OK



                  jenv versions


                  10. Set java version to use (globably)



                  Where XX matches one of the items in the versions list above.



                  jenv global XX


                  Check java version



                  java -version


                  Check jenv versions



                  Should also indicate the current version being used with an asterisk.



                  jenv versions


                  DONE





                  Quick future reference



                  To change java versions



                  ... See the list of available java versions



                  jenv versions


                  ... then, where XX matches an item in the list above



                  jenv global XX





                  share|improve this answer


























                  • Additionally, restart your terminal after brew cask install java*

                    – squeeish
                    Nov 22 '18 at 2:29











                  • it works on Mojave too, thanks

                    – Rizky Ariestiyansyah
                    Mar 7 at 7:16











                  • Clear and great explanation step by step.

                    – Ritesh Singh
                    Mar 12 at 16:37
















                  72














                  For macOS Sierra 420



                  This guide was cobbled together from various sources (replies above as well as other posts), and works perfect.



                  0. If you haven't already, install homebrew.



                  See https://brew.sh/



                  1. Install jenv



                  brew install jenv


                  2. Add jenv to the bash profile



                  if which jenv > /dev/null; then eval "$(jenv init -)"; fi


                  3. Add jenv to your path



                  export PATH="$HOME/.jenv/shims:$PATH"


                  4. Tap "caskroom/versions"



                  FYI: "Tap" extends brew's list of available repos it can install, above and beyond brew's default list of available repos.



                  brew tap caskroom/versions


                  5. Install the latest version of java



                  brew cask install java


                  6. Install java 6 (or 7 or 8 whatever you need)



                  brew cask install java6
                  #brew cask install java7
                  #brew cask install java8


                  ? Maybe close and restart Terminal so it sees any new ENV vars that got setup.



                  7. Review Installations



                  All Java version get installed here: /Library/Java/JavaVirtualMachines lets take a look.



                  ls -la /Library/Java/JavaVirtualMachines


                  8. Add each path to jenv one-at-a-time.



                  We need to add "/Contents/Home" to the version folder.
                  WARNING: Use the actual paths on your machine... these are just EXAMPLE's



                  jenv add /Library/Java/JavaVirtualMachines/1.6.0___EXAMPLE___/Contents/Home
                  jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk___EXAMPLE___/Contents/Home


                  9. Check if jenv registered OK



                  jenv versions


                  10. Set java version to use (globably)



                  Where XX matches one of the items in the versions list above.



                  jenv global XX


                  Check java version



                  java -version


                  Check jenv versions



                  Should also indicate the current version being used with an asterisk.



                  jenv versions


                  DONE





                  Quick future reference



                  To change java versions



                  ... See the list of available java versions



                  jenv versions


                  ... then, where XX matches an item in the list above



                  jenv global XX





                  share|improve this answer


























                  • Additionally, restart your terminal after brew cask install java*

                    – squeeish
                    Nov 22 '18 at 2:29











                  • it works on Mojave too, thanks

                    – Rizky Ariestiyansyah
                    Mar 7 at 7:16











                  • Clear and great explanation step by step.

                    – Ritesh Singh
                    Mar 12 at 16:37














                  72












                  72








                  72







                  For macOS Sierra 420



                  This guide was cobbled together from various sources (replies above as well as other posts), and works perfect.



                  0. If you haven't already, install homebrew.



                  See https://brew.sh/



                  1. Install jenv



                  brew install jenv


                  2. Add jenv to the bash profile



                  if which jenv > /dev/null; then eval "$(jenv init -)"; fi


                  3. Add jenv to your path



                  export PATH="$HOME/.jenv/shims:$PATH"


                  4. Tap "caskroom/versions"



                  FYI: "Tap" extends brew's list of available repos it can install, above and beyond brew's default list of available repos.



                  brew tap caskroom/versions


                  5. Install the latest version of java



                  brew cask install java


                  6. Install java 6 (or 7 or 8 whatever you need)



                  brew cask install java6
                  #brew cask install java7
                  #brew cask install java8


                  ? Maybe close and restart Terminal so it sees any new ENV vars that got setup.



                  7. Review Installations



                  All Java version get installed here: /Library/Java/JavaVirtualMachines lets take a look.



                  ls -la /Library/Java/JavaVirtualMachines


                  8. Add each path to jenv one-at-a-time.



                  We need to add "/Contents/Home" to the version folder.
                  WARNING: Use the actual paths on your machine... these are just EXAMPLE's



                  jenv add /Library/Java/JavaVirtualMachines/1.6.0___EXAMPLE___/Contents/Home
                  jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk___EXAMPLE___/Contents/Home


                  9. Check if jenv registered OK



                  jenv versions


                  10. Set java version to use (globably)



                  Where XX matches one of the items in the versions list above.



                  jenv global XX


                  Check java version



                  java -version


                  Check jenv versions



                  Should also indicate the current version being used with an asterisk.



                  jenv versions


                  DONE





                  Quick future reference



                  To change java versions



                  ... See the list of available java versions



                  jenv versions


                  ... then, where XX matches an item in the list above



                  jenv global XX





                  share|improve this answer















                  For macOS Sierra 420



                  This guide was cobbled together from various sources (replies above as well as other posts), and works perfect.



                  0. If you haven't already, install homebrew.



                  See https://brew.sh/



                  1. Install jenv



                  brew install jenv


                  2. Add jenv to the bash profile



                  if which jenv > /dev/null; then eval "$(jenv init -)"; fi


                  3. Add jenv to your path



                  export PATH="$HOME/.jenv/shims:$PATH"


                  4. Tap "caskroom/versions"



                  FYI: "Tap" extends brew's list of available repos it can install, above and beyond brew's default list of available repos.



                  brew tap caskroom/versions


                  5. Install the latest version of java



                  brew cask install java


                  6. Install java 6 (or 7 or 8 whatever you need)



                  brew cask install java6
                  #brew cask install java7
                  #brew cask install java8


                  ? Maybe close and restart Terminal so it sees any new ENV vars that got setup.



                  7. Review Installations



                  All Java version get installed here: /Library/Java/JavaVirtualMachines lets take a look.



                  ls -la /Library/Java/JavaVirtualMachines


                  8. Add each path to jenv one-at-a-time.



                  We need to add "/Contents/Home" to the version folder.
                  WARNING: Use the actual paths on your machine... these are just EXAMPLE's



                  jenv add /Library/Java/JavaVirtualMachines/1.6.0___EXAMPLE___/Contents/Home
                  jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk___EXAMPLE___/Contents/Home


                  9. Check if jenv registered OK



                  jenv versions


                  10. Set java version to use (globably)



                  Where XX matches one of the items in the versions list above.



                  jenv global XX


                  Check java version



                  java -version


                  Check jenv versions



                  Should also indicate the current version being used with an asterisk.



                  jenv versions


                  DONE





                  Quick future reference



                  To change java versions



                  ... See the list of available java versions



                  jenv versions


                  ... then, where XX matches an item in the list above



                  jenv global XX






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 23 '18 at 2:42

























                  answered Dec 7 '17 at 16:49









                  bobbob

                  3,8432429




                  3,8432429













                  • Additionally, restart your terminal after brew cask install java*

                    – squeeish
                    Nov 22 '18 at 2:29











                  • it works on Mojave too, thanks

                    – Rizky Ariestiyansyah
                    Mar 7 at 7:16











                  • Clear and great explanation step by step.

                    – Ritesh Singh
                    Mar 12 at 16:37



















                  • Additionally, restart your terminal after brew cask install java*

                    – squeeish
                    Nov 22 '18 at 2:29











                  • it works on Mojave too, thanks

                    – Rizky Ariestiyansyah
                    Mar 7 at 7:16











                  • Clear and great explanation step by step.

                    – Ritesh Singh
                    Mar 12 at 16:37

















                  Additionally, restart your terminal after brew cask install java*

                  – squeeish
                  Nov 22 '18 at 2:29





                  Additionally, restart your terminal after brew cask install java*

                  – squeeish
                  Nov 22 '18 at 2:29













                  it works on Mojave too, thanks

                  – Rizky Ariestiyansyah
                  Mar 7 at 7:16





                  it works on Mojave too, thanks

                  – Rizky Ariestiyansyah
                  Mar 7 at 7:16













                  Clear and great explanation step by step.

                  – Ritesh Singh
                  Mar 12 at 16:37





                  Clear and great explanation step by step.

                  – Ritesh Singh
                  Mar 12 at 16:37











                  32














                  SDKMAN! is a great tool for using multiple versions of Java, Gradle, Groovy, Kotlin, and other JVM tools on Mac OS. Installation and usage doc are plainly on the main site.



                  (I have no affiliation, just a happy user).



                  As an example usage, if I type the following in a Terminal window, there is a list of available Java SDK versions (edited for brevity):



                  $ sdk list java
                  Available Java Versions
                  + 9ea170
                  > + 8u131
                  7u141-zulu


                  Here + denotes that the version is installed. > denotes which version is currently in use. To install a version:



                  $ sdk install java 7u141-zulu


                  To use a version in this Terminal window:



                  $ sdk use java 9ea170





                  share|improve this answer


























                  • sdkman supports versions starting with java 1.7. If you're willing to use java 1.6 this solution may not be suitable for you.

                    – Aykut Akıncı
                    Mar 7 '18 at 10:56













                  • sdkman is great, but they dont support specific releases within a version. For example Datastax Dev Center only works with 1.8.0_151 but I can't specify that with sdkman. Hopefully they add more versions.

                    – Eduardo Dennis
                    Jun 11 '18 at 14:43











                  • If you have a local version, I think you can install it into SDKMan - sdkman.io/usage#localversion (but I haven't tried it)

                    – Michael Easter
                    Jun 11 '18 at 15:08
















                  32














                  SDKMAN! is a great tool for using multiple versions of Java, Gradle, Groovy, Kotlin, and other JVM tools on Mac OS. Installation and usage doc are plainly on the main site.



                  (I have no affiliation, just a happy user).



                  As an example usage, if I type the following in a Terminal window, there is a list of available Java SDK versions (edited for brevity):



                  $ sdk list java
                  Available Java Versions
                  + 9ea170
                  > + 8u131
                  7u141-zulu


                  Here + denotes that the version is installed. > denotes which version is currently in use. To install a version:



                  $ sdk install java 7u141-zulu


                  To use a version in this Terminal window:



                  $ sdk use java 9ea170





                  share|improve this answer


























                  • sdkman supports versions starting with java 1.7. If you're willing to use java 1.6 this solution may not be suitable for you.

                    – Aykut Akıncı
                    Mar 7 '18 at 10:56













                  • sdkman is great, but they dont support specific releases within a version. For example Datastax Dev Center only works with 1.8.0_151 but I can't specify that with sdkman. Hopefully they add more versions.

                    – Eduardo Dennis
                    Jun 11 '18 at 14:43











                  • If you have a local version, I think you can install it into SDKMan - sdkman.io/usage#localversion (but I haven't tried it)

                    – Michael Easter
                    Jun 11 '18 at 15:08














                  32












                  32








                  32







                  SDKMAN! is a great tool for using multiple versions of Java, Gradle, Groovy, Kotlin, and other JVM tools on Mac OS. Installation and usage doc are plainly on the main site.



                  (I have no affiliation, just a happy user).



                  As an example usage, if I type the following in a Terminal window, there is a list of available Java SDK versions (edited for brevity):



                  $ sdk list java
                  Available Java Versions
                  + 9ea170
                  > + 8u131
                  7u141-zulu


                  Here + denotes that the version is installed. > denotes which version is currently in use. To install a version:



                  $ sdk install java 7u141-zulu


                  To use a version in this Terminal window:



                  $ sdk use java 9ea170





                  share|improve this answer















                  SDKMAN! is a great tool for using multiple versions of Java, Gradle, Groovy, Kotlin, and other JVM tools on Mac OS. Installation and usage doc are plainly on the main site.



                  (I have no affiliation, just a happy user).



                  As an example usage, if I type the following in a Terminal window, there is a list of available Java SDK versions (edited for brevity):



                  $ sdk list java
                  Available Java Versions
                  + 9ea170
                  > + 8u131
                  7u141-zulu


                  Here + denotes that the version is installed. > denotes which version is currently in use. To install a version:



                  $ sdk install java 7u141-zulu


                  To use a version in this Terminal window:



                  $ sdk use java 9ea170






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jul 16 '17 at 23:40

























                  answered Jul 16 '17 at 23:27









                  Michael EasterMichael Easter

                  16.9k75486




                  16.9k75486













                  • sdkman supports versions starting with java 1.7. If you're willing to use java 1.6 this solution may not be suitable for you.

                    – Aykut Akıncı
                    Mar 7 '18 at 10:56













                  • sdkman is great, but they dont support specific releases within a version. For example Datastax Dev Center only works with 1.8.0_151 but I can't specify that with sdkman. Hopefully they add more versions.

                    – Eduardo Dennis
                    Jun 11 '18 at 14:43











                  • If you have a local version, I think you can install it into SDKMan - sdkman.io/usage#localversion (but I haven't tried it)

                    – Michael Easter
                    Jun 11 '18 at 15:08



















                  • sdkman supports versions starting with java 1.7. If you're willing to use java 1.6 this solution may not be suitable for you.

                    – Aykut Akıncı
                    Mar 7 '18 at 10:56













                  • sdkman is great, but they dont support specific releases within a version. For example Datastax Dev Center only works with 1.8.0_151 but I can't specify that with sdkman. Hopefully they add more versions.

                    – Eduardo Dennis
                    Jun 11 '18 at 14:43











                  • If you have a local version, I think you can install it into SDKMan - sdkman.io/usage#localversion (but I haven't tried it)

                    – Michael Easter
                    Jun 11 '18 at 15:08

















                  sdkman supports versions starting with java 1.7. If you're willing to use java 1.6 this solution may not be suitable for you.

                  – Aykut Akıncı
                  Mar 7 '18 at 10:56







                  sdkman supports versions starting with java 1.7. If you're willing to use java 1.6 this solution may not be suitable for you.

                  – Aykut Akıncı
                  Mar 7 '18 at 10:56















                  sdkman is great, but they dont support specific releases within a version. For example Datastax Dev Center only works with 1.8.0_151 but I can't specify that with sdkman. Hopefully they add more versions.

                  – Eduardo Dennis
                  Jun 11 '18 at 14:43





                  sdkman is great, but they dont support specific releases within a version. For example Datastax Dev Center only works with 1.8.0_151 but I can't specify that with sdkman. Hopefully they add more versions.

                  – Eduardo Dennis
                  Jun 11 '18 at 14:43













                  If you have a local version, I think you can install it into SDKMan - sdkman.io/usage#localversion (but I haven't tried it)

                  – Michael Easter
                  Jun 11 '18 at 15:08





                  If you have a local version, I think you can install it into SDKMan - sdkman.io/usage#localversion (but I haven't tried it)

                  – Michael Easter
                  Jun 11 '18 at 15:08











                  7














                  As found on this website
                  So Let’s begin by installing jEnv





                  1. Run this in the terminal



                    brew install https://raw.github.com/gcuisinier/jenv/homebrew/jenv.rb



                  2. Add jEnv to the bash profile



                    if which jenv > /dev/null; then eval "$(jenv init -)"; fi



                  3. When you first install jEnv will not have any JDK associated with it.



                    For example, I just installed JDK 8 but jEnv does not know about it. To check Java versions on jEnv



                    At the moment it only found Java version(jre) on the system. The * shows the version currently selected. Unlike rvm and rbenv, jEnv cannot install JDK for you. You need to install JDK manually from Oracle website.



                  4. Install JDK 6 from Apple website. This will install Java in /System/Library/Java/JavaVirtualMachines/. The reason we are installing Java 6 from Apple website is that SUN did not come up with JDK 6 for MAC, so Apple created/modified its own deployment version.


                  5. Similarly install JDK7 and JDK8.



                  6. Add JDKs to jEnv.



                    JDK 6:



                    JDK 7:
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518ab9bc47d4.png



                    JDK 8:
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abb2c1217.png




                  7. Check the java versions installed using jenv



                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abceb0deb.png




                  8. So now we have 3 versions of Java on our system. To set a default version use the command



                    jenv local <jenv version>


                    Ex – I wanted Jdk 1.6 to start IntelliJ



                    jenv local oracle64-1.6.0.65



                  9. check the java version



                    java -version
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abe376dd0.png




                  That’s it. We now have multiple versions of java and we can switch between them easily. jEnv also has some other features, such as wrappers for Gradle, Ant, Maven, etc, and the ability to set JVM options globally or locally. Check out the documentation for more information.






                  share|improve this answer





















                  • 3





                    Do not put images of your commands, it makes difficult to copy/paste them. To highlight commands, use the backticks "`" for a single word or a short command, or indent your command with 4 spaces on its own line (or multiples of 4 in lists).

                    – Seki
                    Aug 5 '16 at 10:48






                  • 1





                    Thanks Seki. I was struggling to post images and spent a long time trying to format but could not get it right. Thanks for sharing the backticks info.

                    – Dinesh Arora
                    Aug 5 '16 at 17:20






                  • 3





                    I think you may have used the same image four times.

                    – Ellen Spertus
                    May 18 '18 at 20:00
















                  7














                  As found on this website
                  So Let’s begin by installing jEnv





                  1. Run this in the terminal



                    brew install https://raw.github.com/gcuisinier/jenv/homebrew/jenv.rb



                  2. Add jEnv to the bash profile



                    if which jenv > /dev/null; then eval "$(jenv init -)"; fi



                  3. When you first install jEnv will not have any JDK associated with it.



                    For example, I just installed JDK 8 but jEnv does not know about it. To check Java versions on jEnv



                    At the moment it only found Java version(jre) on the system. The * shows the version currently selected. Unlike rvm and rbenv, jEnv cannot install JDK for you. You need to install JDK manually from Oracle website.



                  4. Install JDK 6 from Apple website. This will install Java in /System/Library/Java/JavaVirtualMachines/. The reason we are installing Java 6 from Apple website is that SUN did not come up with JDK 6 for MAC, so Apple created/modified its own deployment version.


                  5. Similarly install JDK7 and JDK8.



                  6. Add JDKs to jEnv.



                    JDK 6:



                    JDK 7:
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518ab9bc47d4.png



                    JDK 8:
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abb2c1217.png




                  7. Check the java versions installed using jenv



                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abceb0deb.png




                  8. So now we have 3 versions of Java on our system. To set a default version use the command



                    jenv local <jenv version>


                    Ex – I wanted Jdk 1.6 to start IntelliJ



                    jenv local oracle64-1.6.0.65



                  9. check the java version



                    java -version
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abe376dd0.png




                  That’s it. We now have multiple versions of java and we can switch between them easily. jEnv also has some other features, such as wrappers for Gradle, Ant, Maven, etc, and the ability to set JVM options globally or locally. Check out the documentation for more information.






                  share|improve this answer





















                  • 3





                    Do not put images of your commands, it makes difficult to copy/paste them. To highlight commands, use the backticks "`" for a single word or a short command, or indent your command with 4 spaces on its own line (or multiples of 4 in lists).

                    – Seki
                    Aug 5 '16 at 10:48






                  • 1





                    Thanks Seki. I was struggling to post images and spent a long time trying to format but could not get it right. Thanks for sharing the backticks info.

                    – Dinesh Arora
                    Aug 5 '16 at 17:20






                  • 3





                    I think you may have used the same image four times.

                    – Ellen Spertus
                    May 18 '18 at 20:00














                  7












                  7








                  7







                  As found on this website
                  So Let’s begin by installing jEnv





                  1. Run this in the terminal



                    brew install https://raw.github.com/gcuisinier/jenv/homebrew/jenv.rb



                  2. Add jEnv to the bash profile



                    if which jenv > /dev/null; then eval "$(jenv init -)"; fi



                  3. When you first install jEnv will not have any JDK associated with it.



                    For example, I just installed JDK 8 but jEnv does not know about it. To check Java versions on jEnv



                    At the moment it only found Java version(jre) on the system. The * shows the version currently selected. Unlike rvm and rbenv, jEnv cannot install JDK for you. You need to install JDK manually from Oracle website.



                  4. Install JDK 6 from Apple website. This will install Java in /System/Library/Java/JavaVirtualMachines/. The reason we are installing Java 6 from Apple website is that SUN did not come up with JDK 6 for MAC, so Apple created/modified its own deployment version.


                  5. Similarly install JDK7 and JDK8.



                  6. Add JDKs to jEnv.



                    JDK 6:



                    JDK 7:
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518ab9bc47d4.png



                    JDK 8:
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abb2c1217.png




                  7. Check the java versions installed using jenv



                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abceb0deb.png




                  8. So now we have 3 versions of Java on our system. To set a default version use the command



                    jenv local <jenv version>


                    Ex – I wanted Jdk 1.6 to start IntelliJ



                    jenv local oracle64-1.6.0.65



                  9. check the java version



                    java -version
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abe376dd0.png




                  That’s it. We now have multiple versions of java and we can switch between them easily. jEnv also has some other features, such as wrappers for Gradle, Ant, Maven, etc, and the ability to set JVM options globally or locally. Check out the documentation for more information.






                  share|improve this answer















                  As found on this website
                  So Let’s begin by installing jEnv





                  1. Run this in the terminal



                    brew install https://raw.github.com/gcuisinier/jenv/homebrew/jenv.rb



                  2. Add jEnv to the bash profile



                    if which jenv > /dev/null; then eval "$(jenv init -)"; fi



                  3. When you first install jEnv will not have any JDK associated with it.



                    For example, I just installed JDK 8 but jEnv does not know about it. To check Java versions on jEnv



                    At the moment it only found Java version(jre) on the system. The * shows the version currently selected. Unlike rvm and rbenv, jEnv cannot install JDK for you. You need to install JDK manually from Oracle website.



                  4. Install JDK 6 from Apple website. This will install Java in /System/Library/Java/JavaVirtualMachines/. The reason we are installing Java 6 from Apple website is that SUN did not come up with JDK 6 for MAC, so Apple created/modified its own deployment version.


                  5. Similarly install JDK7 and JDK8.



                  6. Add JDKs to jEnv.



                    JDK 6:



                    JDK 7:
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518ab9bc47d4.png



                    JDK 8:
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abb2c1217.png




                  7. Check the java versions installed using jenv



                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abceb0deb.png




                  8. So now we have 3 versions of Java on our system. To set a default version use the command



                    jenv local <jenv version>


                    Ex – I wanted Jdk 1.6 to start IntelliJ



                    jenv local oracle64-1.6.0.65



                  9. check the java version



                    java -version
                    http://javahabi@javahabit.com/wp-content/uploads/2015/03/img_5518abe376dd0.png




                  That’s it. We now have multiple versions of java and we can switch between them easily. jEnv also has some other features, such as wrappers for Gradle, Ant, Maven, etc, and the ability to set JVM options globally or locally. Check out the documentation for more information.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 26 '18 at 1:43

























                  answered Jul 20 '16 at 3:01









                  Dinesh AroraDinesh Arora

                  1,07611423




                  1,07611423








                  • 3





                    Do not put images of your commands, it makes difficult to copy/paste them. To highlight commands, use the backticks "`" for a single word or a short command, or indent your command with 4 spaces on its own line (or multiples of 4 in lists).

                    – Seki
                    Aug 5 '16 at 10:48






                  • 1





                    Thanks Seki. I was struggling to post images and spent a long time trying to format but could not get it right. Thanks for sharing the backticks info.

                    – Dinesh Arora
                    Aug 5 '16 at 17:20






                  • 3





                    I think you may have used the same image four times.

                    – Ellen Spertus
                    May 18 '18 at 20:00














                  • 3





                    Do not put images of your commands, it makes difficult to copy/paste them. To highlight commands, use the backticks "`" for a single word or a short command, or indent your command with 4 spaces on its own line (or multiples of 4 in lists).

                    – Seki
                    Aug 5 '16 at 10:48






                  • 1





                    Thanks Seki. I was struggling to post images and spent a long time trying to format but could not get it right. Thanks for sharing the backticks info.

                    – Dinesh Arora
                    Aug 5 '16 at 17:20






                  • 3





                    I think you may have used the same image four times.

                    – Ellen Spertus
                    May 18 '18 at 20:00








                  3




                  3





                  Do not put images of your commands, it makes difficult to copy/paste them. To highlight commands, use the backticks "`" for a single word or a short command, or indent your command with 4 spaces on its own line (or multiples of 4 in lists).

                  – Seki
                  Aug 5 '16 at 10:48





                  Do not put images of your commands, it makes difficult to copy/paste them. To highlight commands, use the backticks "`" for a single word or a short command, or indent your command with 4 spaces on its own line (or multiples of 4 in lists).

                  – Seki
                  Aug 5 '16 at 10:48




                  1




                  1





                  Thanks Seki. I was struggling to post images and spent a long time trying to format but could not get it right. Thanks for sharing the backticks info.

                  – Dinesh Arora
                  Aug 5 '16 at 17:20





                  Thanks Seki. I was struggling to post images and spent a long time trying to format but could not get it right. Thanks for sharing the backticks info.

                  – Dinesh Arora
                  Aug 5 '16 at 17:20




                  3




                  3





                  I think you may have used the same image four times.

                  – Ellen Spertus
                  May 18 '18 at 20:00





                  I think you may have used the same image four times.

                  – Ellen Spertus
                  May 18 '18 at 20:00











                  5














                  I find this Java version manager called Jabba recently and the usage is very similar to version managers of other languages like rvm(ruby), nvm(node), pyenv(python), etc. Also it's cross platform so definitely it can be used on Mac.



                  After installation, it will create a dir in ~/.jabba to put all the Java versions you install. It "Supports installation of Oracle JDK (default) / Server JRE, Zulu OpenJDK (since 0.3.0), IBM SDK, Java Technology Edition (since 0.6.0) and from custom URLs.".



                  Basic usage is listed on their Github. A quick summary to start:



                  curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh

                  # install Oracle JDK
                  jabba install 1.8 # "jabba use 1.8" will be called automatically
                  jabba install 1.7 # "jabba use 1.7" will be called automatically

                  # list all installed JDK's
                  jabba ls

                  # switch to a different version of JDK
                  jabba use 1.8





                  share|improve this answer




























                    5














                    I find this Java version manager called Jabba recently and the usage is very similar to version managers of other languages like rvm(ruby), nvm(node), pyenv(python), etc. Also it's cross platform so definitely it can be used on Mac.



                    After installation, it will create a dir in ~/.jabba to put all the Java versions you install. It "Supports installation of Oracle JDK (default) / Server JRE, Zulu OpenJDK (since 0.3.0), IBM SDK, Java Technology Edition (since 0.6.0) and from custom URLs.".



                    Basic usage is listed on their Github. A quick summary to start:



                    curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh

                    # install Oracle JDK
                    jabba install 1.8 # "jabba use 1.8" will be called automatically
                    jabba install 1.7 # "jabba use 1.7" will be called automatically

                    # list all installed JDK's
                    jabba ls

                    # switch to a different version of JDK
                    jabba use 1.8





                    share|improve this answer


























                      5












                      5








                      5







                      I find this Java version manager called Jabba recently and the usage is very similar to version managers of other languages like rvm(ruby), nvm(node), pyenv(python), etc. Also it's cross platform so definitely it can be used on Mac.



                      After installation, it will create a dir in ~/.jabba to put all the Java versions you install. It "Supports installation of Oracle JDK (default) / Server JRE, Zulu OpenJDK (since 0.3.0), IBM SDK, Java Technology Edition (since 0.6.0) and from custom URLs.".



                      Basic usage is listed on their Github. A quick summary to start:



                      curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh

                      # install Oracle JDK
                      jabba install 1.8 # "jabba use 1.8" will be called automatically
                      jabba install 1.7 # "jabba use 1.7" will be called automatically

                      # list all installed JDK's
                      jabba ls

                      # switch to a different version of JDK
                      jabba use 1.8





                      share|improve this answer













                      I find this Java version manager called Jabba recently and the usage is very similar to version managers of other languages like rvm(ruby), nvm(node), pyenv(python), etc. Also it's cross platform so definitely it can be used on Mac.



                      After installation, it will create a dir in ~/.jabba to put all the Java versions you install. It "Supports installation of Oracle JDK (default) / Server JRE, Zulu OpenJDK (since 0.3.0), IBM SDK, Java Technology Edition (since 0.6.0) and from custom URLs.".



                      Basic usage is listed on their Github. A quick summary to start:



                      curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh

                      # install Oracle JDK
                      jabba install 1.8 # "jabba use 1.8" will be called automatically
                      jabba install 1.7 # "jabba use 1.7" will be called automatically

                      # list all installed JDK's
                      jabba ls

                      # switch to a different version of JDK
                      jabba use 1.8






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 26 '17 at 20:19









                      York YangYork Yang

                      31648




                      31648























                          4














                          I am using Mac OS X 10.9.5. This is how I manage multiple JDK/JRE on my machine when I need one version to run application A and use another version for application B.



                          I created the following script after getting some help online.



                          #!bin/sh
                          function setjdk() {
                          if [ $# -ne 0 ]; then
                          removeFromPath '/Library/Java/JavaVirtualMachines/'
                          if [ -n "${JAVA_HOME+x}" ]; then
                          removeFromPath $JAVA_HOME
                          fi
                          export JAVA_HOME=/Library/Java/JavaVirtualMachines/$1/Contents/Home
                          export PATH=$JAVA_HOME/bin:$PATH
                          fi
                          }
                          function removeFromPath() {
                          export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
                          }
                          #setjdk jdk1.8.0_60.jdk
                          setjdk jdk1.7.0_15.jdk


                          I put the above script in .profile file. Just open terminal, type vi .profile, append the script with the above snippet and save it. Once your out type source .profile, this will run your profile script without you having to restart the terminal. Now type java -version it should show 1.7 as your current version. If you intend to change it to 1.8 then comment the line setjdk jdk1.7.0_15.jdk and uncomment the line setjdk jdk1.8.0_60.jdk. Save the script and run it again with source command. I use this mechanism to manage multiple versions of JDK/JRE when I have to compile 2 different Maven projects which need different java versions.






                          share|improve this answer




























                            4














                            I am using Mac OS X 10.9.5. This is how I manage multiple JDK/JRE on my machine when I need one version to run application A and use another version for application B.



                            I created the following script after getting some help online.



                            #!bin/sh
                            function setjdk() {
                            if [ $# -ne 0 ]; then
                            removeFromPath '/Library/Java/JavaVirtualMachines/'
                            if [ -n "${JAVA_HOME+x}" ]; then
                            removeFromPath $JAVA_HOME
                            fi
                            export JAVA_HOME=/Library/Java/JavaVirtualMachines/$1/Contents/Home
                            export PATH=$JAVA_HOME/bin:$PATH
                            fi
                            }
                            function removeFromPath() {
                            export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
                            }
                            #setjdk jdk1.8.0_60.jdk
                            setjdk jdk1.7.0_15.jdk


                            I put the above script in .profile file. Just open terminal, type vi .profile, append the script with the above snippet and save it. Once your out type source .profile, this will run your profile script without you having to restart the terminal. Now type java -version it should show 1.7 as your current version. If you intend to change it to 1.8 then comment the line setjdk jdk1.7.0_15.jdk and uncomment the line setjdk jdk1.8.0_60.jdk. Save the script and run it again with source command. I use this mechanism to manage multiple versions of JDK/JRE when I have to compile 2 different Maven projects which need different java versions.






                            share|improve this answer


























                              4












                              4








                              4







                              I am using Mac OS X 10.9.5. This is how I manage multiple JDK/JRE on my machine when I need one version to run application A and use another version for application B.



                              I created the following script after getting some help online.



                              #!bin/sh
                              function setjdk() {
                              if [ $# -ne 0 ]; then
                              removeFromPath '/Library/Java/JavaVirtualMachines/'
                              if [ -n "${JAVA_HOME+x}" ]; then
                              removeFromPath $JAVA_HOME
                              fi
                              export JAVA_HOME=/Library/Java/JavaVirtualMachines/$1/Contents/Home
                              export PATH=$JAVA_HOME/bin:$PATH
                              fi
                              }
                              function removeFromPath() {
                              export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
                              }
                              #setjdk jdk1.8.0_60.jdk
                              setjdk jdk1.7.0_15.jdk


                              I put the above script in .profile file. Just open terminal, type vi .profile, append the script with the above snippet and save it. Once your out type source .profile, this will run your profile script without you having to restart the terminal. Now type java -version it should show 1.7 as your current version. If you intend to change it to 1.8 then comment the line setjdk jdk1.7.0_15.jdk and uncomment the line setjdk jdk1.8.0_60.jdk. Save the script and run it again with source command. I use this mechanism to manage multiple versions of JDK/JRE when I have to compile 2 different Maven projects which need different java versions.






                              share|improve this answer













                              I am using Mac OS X 10.9.5. This is how I manage multiple JDK/JRE on my machine when I need one version to run application A and use another version for application B.



                              I created the following script after getting some help online.



                              #!bin/sh
                              function setjdk() {
                              if [ $# -ne 0 ]; then
                              removeFromPath '/Library/Java/JavaVirtualMachines/'
                              if [ -n "${JAVA_HOME+x}" ]; then
                              removeFromPath $JAVA_HOME
                              fi
                              export JAVA_HOME=/Library/Java/JavaVirtualMachines/$1/Contents/Home
                              export PATH=$JAVA_HOME/bin:$PATH
                              fi
                              }
                              function removeFromPath() {
                              export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
                              }
                              #setjdk jdk1.8.0_60.jdk
                              setjdk jdk1.7.0_15.jdk


                              I put the above script in .profile file. Just open terminal, type vi .profile, append the script with the above snippet and save it. Once your out type source .profile, this will run your profile script without you having to restart the terminal. Now type java -version it should show 1.7 as your current version. If you intend to change it to 1.8 then comment the line setjdk jdk1.7.0_15.jdk and uncomment the line setjdk jdk1.8.0_60.jdk. Save the script and run it again with source command. I use this mechanism to manage multiple versions of JDK/JRE when I have to compile 2 different Maven projects which need different java versions.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Sep 18 '15 at 22:47









                              ChaitanyaBhattChaitanyaBhatt

                              52658




                              52658























                                  3














                                  Jenv on Mac Sierra:



                                  if not working after install, do this bug fix to add java executable to path



                                  export PATH="$HOME/.jenv/shims:$PATH"


                                  even though eval "$(jenv init -)" could do this job. The reason is /bin folder is not there anymore as describe in it's homepage, but shim folder is used as /bin instead.




                                  • Make sure ~/.jenv is there


                                  • which java may print /Library/...

                                  • jenv global 1.8

                                  • jenv shell 1.8


                                  Eventually, which java gives you:




                                  /Users/xxxx/.jenv/shims/java







                                  share|improve this answer




























                                    3














                                    Jenv on Mac Sierra:



                                    if not working after install, do this bug fix to add java executable to path



                                    export PATH="$HOME/.jenv/shims:$PATH"


                                    even though eval "$(jenv init -)" could do this job. The reason is /bin folder is not there anymore as describe in it's homepage, but shim folder is used as /bin instead.




                                    • Make sure ~/.jenv is there


                                    • which java may print /Library/...

                                    • jenv global 1.8

                                    • jenv shell 1.8


                                    Eventually, which java gives you:




                                    /Users/xxxx/.jenv/shims/java







                                    share|improve this answer


























                                      3












                                      3








                                      3







                                      Jenv on Mac Sierra:



                                      if not working after install, do this bug fix to add java executable to path



                                      export PATH="$HOME/.jenv/shims:$PATH"


                                      even though eval "$(jenv init -)" could do this job. The reason is /bin folder is not there anymore as describe in it's homepage, but shim folder is used as /bin instead.




                                      • Make sure ~/.jenv is there


                                      • which java may print /Library/...

                                      • jenv global 1.8

                                      • jenv shell 1.8


                                      Eventually, which java gives you:




                                      /Users/xxxx/.jenv/shims/java







                                      share|improve this answer













                                      Jenv on Mac Sierra:



                                      if not working after install, do this bug fix to add java executable to path



                                      export PATH="$HOME/.jenv/shims:$PATH"


                                      even though eval "$(jenv init -)" could do this job. The reason is /bin folder is not there anymore as describe in it's homepage, but shim folder is used as /bin instead.




                                      • Make sure ~/.jenv is there


                                      • which java may print /Library/...

                                      • jenv global 1.8

                                      • jenv shell 1.8


                                      Eventually, which java gives you:




                                      /Users/xxxx/.jenv/shims/java








                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Oct 31 '16 at 1:06









                                      CodeFarmerCodeFarmer

                                      1,6861624




                                      1,6861624























                                          0














                                          Here's a more DRY version for bash (Based on Vegard's answer)



                                          Replace 1.7 and 1.8 with whatever versions you are interested with
                                          and you'll get an alias called 'javaX'; where 'X' is the java version (7 / 8 in the snippet below) that will allow you to easily switch versions



                                          for version in 1.7 1.8; do
                                          v="${version: -1}"
                                          h=JAVA_"$v"_HOME

                                          export "$h"=$(/usr/libexec/java_home -v $version)

                                          alias "java$v"="export JAVA_HOME=$$h"
                                          done





                                          share|improve this answer




























                                            0














                                            Here's a more DRY version for bash (Based on Vegard's answer)



                                            Replace 1.7 and 1.8 with whatever versions you are interested with
                                            and you'll get an alias called 'javaX'; where 'X' is the java version (7 / 8 in the snippet below) that will allow you to easily switch versions



                                            for version in 1.7 1.8; do
                                            v="${version: -1}"
                                            h=JAVA_"$v"_HOME

                                            export "$h"=$(/usr/libexec/java_home -v $version)

                                            alias "java$v"="export JAVA_HOME=$$h"
                                            done





                                            share|improve this answer


























                                              0












                                              0








                                              0







                                              Here's a more DRY version for bash (Based on Vegard's answer)



                                              Replace 1.7 and 1.8 with whatever versions you are interested with
                                              and you'll get an alias called 'javaX'; where 'X' is the java version (7 / 8 in the snippet below) that will allow you to easily switch versions



                                              for version in 1.7 1.8; do
                                              v="${version: -1}"
                                              h=JAVA_"$v"_HOME

                                              export "$h"=$(/usr/libexec/java_home -v $version)

                                              alias "java$v"="export JAVA_HOME=$$h"
                                              done





                                              share|improve this answer













                                              Here's a more DRY version for bash (Based on Vegard's answer)



                                              Replace 1.7 and 1.8 with whatever versions you are interested with
                                              and you'll get an alias called 'javaX'; where 'X' is the java version (7 / 8 in the snippet below) that will allow you to easily switch versions



                                              for version in 1.7 1.8; do
                                              v="${version: -1}"
                                              h=JAVA_"$v"_HOME

                                              export "$h"=$(/usr/libexec/java_home -v $version)

                                              alias "java$v"="export JAVA_HOME=$$h"
                                              done






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Apr 5 '18 at 12:51









                                              elad.chenelad.chen

                                              1,55241829




                                              1,55241829






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26252591%2fmac-os-x-and-multiple-java-versions%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                                                  Alcedinidae

                                                  Can an atomic nucleus contain both particles and antiparticles? [duplicate]