Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install java 7 on mac in custom location?

Tags:

java

macos

java-7

I want to install java 7 on mac silently. I am unable to find any documentation/links on the same.
Also I don't want it in /Library. Is it possible to install the same on any custom location.
I am very new to mac any help is highly appreciated.

like image 378
amod Avatar asked Mar 05 '13 06:03

amod


2 Answers

Just to make the steps from @HawkMage more explicit (and illustrate them working with JDK8):

  1. Download the binary (eg, jdk-8u5-macosx-x64.dmg) from Oracle
  2. Double click from Finder to mount the Volume. Ignore the window with the “JDK 8 Update x.pkg”
  3. Use pkgutil to expand the contents of the package into a temporary directory:

    $ pkgutil --expand  /Volumes/JDK\ 8\ Update\ 05/JDK\ 8\ Update\ 05.pkg /tmp/jdkpkg
    
  4. Then, change to that dir and use cpio to expand the Payload file:

    $ cd /tmp/jdkpkg
    $ cpio -i < ./jdk18005.pkg/Payload
    
  5. Finally, move the Home dir to wherever you’d like your JAVA_HOME to live

    $ mv Contents/Home /mytools/jdk-1.8.0_05
    
like image 147
ckhan Avatar answered Sep 20 '22 20:09

ckhan


Unfortunately the "standard" Java that comes on OS X is packaged in a very non-standard way.

It is not as easy as linux, the DMG downloaded gives you a PKG file that if you run it just installs Java. This is not useful if you are trying to keep the standard Java that comes with OS X intact.

What I do is download the DMG file from Oracle and open it but instead of running the PKG I use pkgutil to extract the contents of the package. You will find a directory named jdk*.pkg and in it you will see a file named Payload. This is a GZipped CPIO file and you can extract it by cating it and piping it into cpio -zi. From this you will now have a directory named Contents and under it you will find a directory named Home. This "Home" directory is the what you would normially get with the Linux tar.gz Java download. You can copy it to wherever you want and put the bin directory in your path and set the JAVA_HOME to it and you are good to go.

like image 40
HawkMage Avatar answered Sep 20 '22 20:09

HawkMage