How To Install Java 7 on Mac OS X


For most, this would come in handy with those using the latest browser extensions/add-ons that use Java, especially version 7 (in the time of this writing). There are two ways to go about this. First, for most users, they just need the JRE. The second are those doing development work and need the JDK.

Before we start the installation process, let’s start with some preflight check and do the following in Terminal prompt:

$ java -version

This will give you 1.6.x of some degree. Now, let’s start the installation.

If you just need the JRE:

  1. Download the JRE here.
  2. Follow the instructions, and install onto your OS X system.
  3. In your ~/.profile, ((Or .bashrc, .bash_profile, etc.)) add the following:
    export JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
    
  4. Open a new Terminal window, and run the following to check you are running the intended version:
    $ java -version
    

    This should give you something like the following results:

    $ java -version
    java version "1.7.0_67"
    Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
    Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
    

For those that need the JDK, and running Homebrew, you may do the following:

  1. Download the JDK here.
  2. Install jenv via Homebrew: ((Be sure to brew udpate and run brew doctor before adding any new packages, always.))
    $ brew tap jenv/jenv
    $ bre install jenv
    

    More info here.

  3. Add the following in your Bash files by running these in Terminal: ((Again, these can be .bashrc, .bash_profile, etc.))
    $ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.profile
    $ echo 'eval "$(jenv init -)"' >> ~/.profile
    
  4. Configure jenv by running the following for example:
    $ jenv add /Library/Java/JavaVirtualMachines/jdk17011.jdk/Contents/Home
    oracle64-1.7.0.11 added
    
  5. Last but not least, check that you are running the intended version in Terminal:
    $ java -version
    

I hope that helps.