In an, I described how to install the latest version of the Oracle Java JDK using. What hadn’t been completely obvious to me when I wrote the original blog post is that the ‘java’ cask will install the latest major version of the JDK.
As a result, when I upgraded my JDK install today, I ended up with an upgrade from Java 8 to Java 9. On my personal machine that’s not a problem, but what if I wanted to stick with a specific major version of Java?
Option 2: Installing the Latest Java Version from Oracle. The other option to get the latest version of Java is to simply download it from Oracle and install manually. Grab the newest Java from Oracle; Most casual Mac users only need to get the JRE (Java Runtime Environment) and not the full JDK (Java Development Kit).
Turns out, there is actually another cask called “versions” that allows you to do exactly that. With just the ‘java’ cask installed, searching casks for “java” results in the following output. My-macpro: timo$ brew cask search 'java.' Exact Match java ✔ Partial Matches eclipse-java java-jdk-javadoc netbeans-java-ee netbeans-java-se yourkit-java-profiler my-macpro: timo$ java -version java version '9' Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode) my-macpro: timo$ As you can see, it finds a single ‘java’ cask, which is the one I used in the previous blog post to install the current version of the JDK. Now let’s tap the “versions” cask as well. My-macpro: timo$ brew tap caskroom/versions Tapping caskroom/versions Cloning into '/usr/local/Homebrew/Library/Taps/caskroom/homebrew-versions'.
Remote: Counting objects: 196, done. Remote: Compressing objects: 100% (193/193), done. Remote: Total 196 (delta 15), reused 45 (delta 1), pack-reused 0 Receiving objects: 100% (196/196), 78.89 KiB 4.64 MiB/s, done.
Resolving deltas: 100% (15/15), done. Tapped 0 formulae (214 files, 295.9KB) With the ‘versions’ cask tapped, let’s search the casks for “java” again: my-macpro: timo$ brew cask search 'java.' Exact Match java ✔ Partial Matches charles-applejava java-jdk-javadoc java8 netbeans-java-se eclipse-java java6 netbeans-java-ee yourkit-java-profiler You can see that the search now finds a few more casks, namely “charles-applejava”, “java6” and “java8”. Running ‘brew cask info’ on the two java casks shows that they’ll allow you to install the latest Java 6 and Java 8 JDKs. My-macpro: timo$ brew cask info java6 java6: 1.6.065 Not installed From: Name Java Standard Edition Development Kit Artifacts JavaForOSX.pkg (Pkg) my-macpro: timo$ brew cask info java8 java8: 1.8.0144-b01,090f390dda5b47b9b721c7dfaa008135 Not installed From: Name Java Standard Edition Development Kit Artifacts JDK 8 Update 144.pkg (Pkg) Caveats This Cask makes minor modifications to the JRE to prevent issues with packaged applications, as discussed here: If your Java application still asks for JRE installation, you might need to reboot or logout/login. Installing this Cask means you have AGREED to the Oracle Binary Code License Agreement for Java SE at After tapping the ‘versions’ cask, you can install the aforementioned Java 8, by running. My-macpro: timo$ brew cask install java8 Caveats This Cask makes minor modifications to the JRE to prevent issues with packaged applications, as discussed here: If your Java application still asks for JRE installation, you might need to reboot or logout/login.
Installing this Cask means you have AGREED to the Oracle Binary Code License Agreement for Java SE at Satisfying dependencies Downloading ######################################################################## 100.0% Verifying checksum for Cask java8 Installing Cask java8 Running installer for java8; your password may be necessary. Package installers may write to any location; options such as -appdir are ignored. Password: installer: Package name is JDK 8 Update 144 installer: Installing at base path / installer: The install was successful. ? java8 was successfully installed! At this particular point, the default Java still points to /usr/bin/java. This launcher binary will start Java 9 by default.
![Jdk on mac Jdk on mac](http://cdn.osxdaily.com/wp-content/uploads/2015/10/install-java-os-x-el-capitan-610x312.jpg)
However, by pointing JAVAHOME to one of the other installations, you can use the newly installed, latest version of Java 8.
That’s the “Java version” you need to know. Downloading the JDK When working with Java, you need to distinguish two Java software package types:. JRE: The “Java Runtime Environment” is necessary to run Java application. You cannot, however, compile Java programs with just the JRE. JDK: The “Java Development Kit” is required when you want to compile Java programs. The JDK includes the JRE, and also comes with Java’s source code.
Remark: Eclipse comes with its own Java compiler. That’s why you don’t need to install a JDK to create Java programs with Eclipse.
Eclipse doesn’t ship with the Java source code though. That’s why we still need the JDK. The JDK for Mac OS X comes as “Java Developer Package”. You can download it here: You’ll need an AppleID to download the JDK.
Fortunately, it’s free but you still need to register it. (Tip: You can use the same you use in the iTunes Store.) After logging in, type “java developer package” in the search field (see screenshot). Make sure the you download the Java Developer Package matching your Java version. In my case, this is “Mac OS X 10.7 Update 1”.
Note: Don’t confuse “10.7” for Java 7. It’s still Java 6. (So don’t download a “10.6” version when you’re running Mac OS X Lion.) Then install the JDK. This will install the JDK under: /Library/Java/JavaVirtualMachines/ Note: There’s also the directory /System/Library/Frameworks/JavaVM.framework/. However, this directory seems to be deprecated. The Java source code will be located here: /Library/Java/JavaVirtualMachines/.jdk/Contents/Home/src.jar Check an already installed JDK To check whether you’ve already installed a JDK, check the list of installed updates (see ) for an entry called “Java Developer Package”.
Note: Unfortunately, the Java Developer Package listed in the list doesn’t have any (visible) version information attached to it. I’m not sure whether the JDK will be updated automatically when a new version becomes available.
To check the actual Java version of the installed JDK, go to /Library/Java/JavaVirtualMachines/ and check whether a package called like “1.6.029-b11-402.jdk” can be found there. In this example, the Java version would be “1.6.029”. Using the JDK in Eclipse On Mac OS X, Eclipse provides an automatic way to determine the directory of the installed JDK.
Go to the Eclipse Settings and open Java – Installed JREs. Then, by clicking on the Search. Button, would find the newly installed JDK. Unfortunately, there seems to be a bug in Eclipse Ingido (3.7 – and probably in earlier versions, too) that prevents this button from working correctly. Clicking on it doesn’t do anything when there’s already one (and only one) JRE listed here; see screenshot. To fix this problem, do the following:.
Duplicate the existing entry (by hitting the Duplicate. Button). Delete the original entry; it’s the one with checked checkbox in front of it. Then click Search. This should add two new entries to the list (see next screenshot). Delete the entry you’ve created in step 1 (i.e. The duplicate of the original entry).
Check one of the remaining entries. Note: The new two entries are linked. If you check one, both will be checked. Also, you can’t delete the entry for /System/Library/Java/.
Trying to do so will delete the other entry. Close the Settings dialog with OK. Restart Eclipse. This will remove the wrong entry (the one for /System/Library/Java/.) from the list. Manually adding a JDK If you want (for any reason) to add the JDK manually, here’s how to do this:. Go to Installed JREs in the Eclipse Settings. Choose “MacOS X VM” and hit Next.
Specify /Library/Java/JavaVirtualMachines/.jdk/Contents/Home/ under JRE Home. Note: You need to type/paste the directory directly into the field. You can’t use the Directory. As the directories in the JavaVirtualMachines directory are so called “Mac OS X packages”.
These directories are displayed as files and you can’t browse their contents from within the dialog. Give the JDK a meaningful name and hit Finish.