9

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.

amod
  • 4,190
  • 10
  • 49
  • 75

5 Answers5

23

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
    
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
ckhan
  • 4,771
  • 24
  • 26
21

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.

HawkMage
  • 211
  • 1
  • 3
4

Just like in Linux, you can pretty much install Java anywhere you like on a mac. You just need to make sure that you add the Java executable to the path or create a symbolic link of the java executable and put it in the /usr/bin/ directory so it can be executed anywhere.

To add Java to path:

1) Modify .bash_profile found in your home director.

2) Add this line: export PATH=/yourjavadir/bin:$PATH

3) Save and exit

4) Then do source .bash_profile to reload the file. You'll only need to do this one time.

To create a symbolic link:

ln -s /yourjavadir/java /usr/bin/java
Jay Q.
  • 4,979
  • 3
  • 33
  • 36
  • Yes, you can. Just delete it and create your own. If I've answered your question please mark it answered. Thanks :) – Jay Q. Mar 06 '13 at 13:10
  • Hey Jay I have marked it. Can you help me in answering this question http://stackoverflow.com/questions/14806709/application-is-using-java-6-instead-of-7-in-mac-osx. it has a bounty from my side. :) – amod Mar 06 '13 at 18:09
1

I had the same issue and just managed to figure it out.

  1. Download and unzip the Java binary in your custom directory. For eg -

/Users/myuser/Documents/jre1.8.0_25.jre

  1. Update your .bash_profile with the following parameters

export JAVA_HOME=/Users/a514624/Documents/jre1.8.0_25.jre/Contents/Home export PATH=$PATH:$JAVA_HOME/bin

  1. Close the terminal window and open it again. Alternately, you could type the command 'source .bash_profile'.

After these steps, if you type java -version on the command prompt, you would see it reflecting the version which you were hoping to see -

$ java -version java version "1.8.0_25" Java(TM) SE Runtime Environment (build 1.8.0_25-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

  1. Unlink the existing Java softlink (would require root/elevated privileges) root$ unlink /usr/bin/java

  2. Create a symbolic link to the new Java installation root$ ln -s /Users/myuser/Documents/jre1.8.0_25.jre/Contents/Home/bin/java /usr/bin/java

Thats it. Life is beautiful after this. Hope this helps!

mmukhe
  • 668
  • 9
  • 22
0

If you just need JRE/Java Runtime Edition then previous answers arecorrect but if you need JRE and JDK (Java Development Kit) then simply go to below link and select the mac and run the dmg and it's much better and by far the easiest.

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

grepit
  • 21,260
  • 6
  • 105
  • 81