Page tree
Skip to end of metadata
Go to start of metadata

Introduction

...

Mac OS X

Installation

Untar the Java runtime (instructions to follow).

Add to Class Path for a Session and Particular User

This is my preferred approach. I launch a terminal and make a specific Java version available or the particular session. This change is not permanent and I can load multiple terminal sessions testing with different versions of Java.

From the command line you can just type,

export PATH=~/cmd/jre1.8.0_05.jre/Contents/Home/bin:$PATH
 
java -version # verify
Java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

However, to make things easier you need to script it, but you can not simply add this to a shell script. The reason is the export will only last for the period the script is running. Not very useful executing 

This is because a shell script execution will actually spawn a new child shell. The export only applies to the life time of the child shell. Once it exits you are back to the unchanged father shell.

To resolve this, create a file called, java8.sourcefile,

# Need to have the cmd Java before the sym link java setup by Apple
export PATH=/Users/tin.pham/cmd/jre1.8.0_05.jre/Contents/Home/bin:$PATH

Then execute the source command,

source java8.sourcefile
 
java -version # verify
Java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

 

Change Java for All Users

 

References

Good Q&A on how to change Mac OS X Path - http://unix.stackexchange.com/questions/23426/how-to-alter-path-within-bash-script

Change Java path for all uses (this method pre-empts user/bin) - http://daniel.hepper.net/blog/2011/02/change-order-of-path-entries-on-mac-os-x/
 

  • No labels