Basic methods for installing Java and configuring environment variables on Mac OS

  • 2020-04-01 04:13:58
  • OfStack

The installation
Because Java is not available to all users, OS X does not come with Java by default, and you can install it manually if you need to.

1. http://support.apple.com/kb/DL1572
Download it from apple's website.
http://support.apple.com/downloads/DL1572/en_US/JavaForOSX2014-001.dmg


2. http://www.oracle.com/technetwor... Ownloads/index. HTML
Download the latest Java 8 JDK installation from Oracle.

Input at the terminal after installation


java -version

If the version is displayed, it is installed.

If it shows as follows, it means there is no correct installation and it needs to be redone.


No Java runtime present, requesting install.

Find and set $JAVA_HOME on the MAC

To locate java_home, use the tools command "/usr/libexec/java_home" :

Locate the JAVA:


/usr/libexec/java_home -V

Matching Java Virtual Machines (1):
  1.8.0_25, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

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


You can also use the -v option to list all versions of JAVA_HOME:


$ /usr/libexec/java_home -V

Matching Java Virtual Machines (3):
1.7.0_45, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
1.6.0_65-b14-462, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home


Configuration JAVA_HOME:


$ cat ~/.profile

JAVA_HOME=`/usr/libexec/java_home`
export JAVA_HOME

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
$ source ~/.profile 
$java


Related articles: