Installing and configuring Java on Mac - rajivkanaujia/alphaworks GitHub Wiki

Removing the "system" JVM installed and maintained by Software Update

  • Uninstalling Java 6 to replace with newer version of Java
    $ sudo rm -rf /System/Library/Java/JavaVirtualMachines/1.6.0.jdk
  • Remove any Java Developer Previews
    $ sudo rm -rf /System/Library/Java/JavaVirtualMachines/1.6.0.jdk

Installing Legacy Java 6 runtime

  • If you need to use Java for OS X 2017-001, install the Legacy Java

Installing Java and adding JAVA_HOME

Install latest version of Java

Once you have installed Java, you should be able to type Java on the Terminal to get an output like -

    $ Java
    Usage: java [-options] class [args...]
            (to execute a class)
    or  java [-options] -jar jarfile [args...]
            (to execute a jar file)
    where options include:
        -d32	  use a 32-bit data model if available
        -d64	  use a 64-bit data model if available
        -server	  to select the "server" VM
                    The default VM is server,
                    because you are running on a server-class machine. a server-class machine.
    ......

Simple approach --> Entries in .bash_profile

    # JAVA
    export JAVA_HOME=$(/usr/libexec/java_home)
    export PATH=${PATH}:${JAVA_HOME}/bin

Other options

  • Java will be installed in folder mentioned below. Find the right director / Java version to be used.
    $ ls /Library/Java/JavaVirtualMachines/
  • Adding JAVA_HOME in bash
    $open -e .bash_profile 
  • Add following two options. First uses symbolic link, other is absolute path
    # Option 1
    export JAVA_HOME=$(/usr/libexec/java_home)
    # Option 2
    export JAVA_HOME=”/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home”

Reload the .bash_profile

    $ source .bash_profile

Check the JAVA_HOME setting

     $ echo $JAVA_HOME
    /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
  • Check is synlink to Java is working
    $ /usr/libexec/java_home -V 
    Matching Java Virtual Machines (1):
    1.8.0_31, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home

    /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home

Check if Java is working by issuing two commands mentioned below:

    $ java -version
    java version "1.8.0_60"
    Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
    Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

    $ echo $JAVA_HOME 
    /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home

Note: If you like the instructions here, please refer it on your posts/documentation. Contact me if there are corrections needed.