Take me home

OS X: Extract JDK to folder, without running installer

Written by August Lilleaas, published July 10, 2014

On Linux, I'm used to downloading the JDK as a tarball, extracting it, and setting PATH and JAVA_HOME accordingly. This makes it super-easy to switch Java versions, run multiple older versions, and so on.

I just got a Macbook Air, and the only option for installing Java there, is a .dmg file with a .pkg installer. No wireless. Less space than a nomad. Lame.

How to extract to a folder

Here, a numbered list, to make it easy for you.

  1. Download the installer .dmg files. They contain the good stuff.
  2. Mount the .dmg and copy the .pkg file to somewhere
  3. Open a terminal and cd to the folder you copied the .pkg file into
  4. pkgutil --expand JDK\ 7\ Update\ 60.pkg JDK7u60 - extract pkg file to folder
  5. cd JDK7u60/ - move to the extracted pkg
  6. cd jdk17060.pkg/ - there's a folder with the version number ending with .pkg (but it's just a folder), go there
  7. open Payload - this is a gzipped "ASCII cpio archive (pre-SVR4 or odc)", according to file. The "open" command will extract it using the Archive Utility app.
  8. Done! Now you just need to copy the files.
  9. cp Contents/Home ~/local/jdk_1.7u60

No installer was ever executed. No auto updater will be installed. No global PATH will get whatever "java" you already had overwritten.


Questions or comments?

Feel free to contact me on Twitter, @augustl, or e-mail me at august@augustl.com.