Java Installation on Mac: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Internal=
=Internal=


* [[Java#Subjects|Java]]
* [[Java on Mac]]
* [[Mac#Subjects|Mac]]
* [[Mac#Subjects|Mac]]


Line 15: Line 15:
and a GUI window pops up: "to use the "java" command-line tool you need to install a JDK". More Info ... which says to go to the Oracle site.
and a GUI window pops up: "to use the "java" command-line tool you need to install a JDK". More Info ... which says to go to the Oracle site.


=Oracle SDK Installation=
=Java Vendors=


==Oracle SDK Installation==
Download the latest for Mac (jdk-9.0.1_osx-x64_bin.dmg, jdk-8u25-macosx-x64.dmg or jdk-7u75-macosx-x64.dmg, depending of whether you need Java 9, Java 8 or Java 7).
Download the latest for Mac (jdk-9.0.1_osx-x64_bin.dmg, jdk-8u25-macosx-x64.dmg or jdk-7u75-macosx-x64.dmg, depending of whether you need Java 9, Java 8 or Java 7).


Line 32: Line 33:
  /usr/libexec/java_home
  /usr/libexec/java_home


=JAVA_HOME=
==Amazon Corretto Installation==
{{Internal|Corretto#Mac|Amazon Corretto Installation on Mac}}
 
=<span id='JAVA_HOME'></span><tt>JAVA_HOME</tt> and <tt>/usr/libexec/java_home</tt>=


For a standard installation the value of <tt>JAVA_HOME</tt> is returned by the result of <tt>/usr/libexec/java_home</tt>:
For a standard installation the value of <tt>JAVA_HOME</tt> is returned by the result of <tt>/usr/libexec/java_home</tt>:
Line 48: Line 52:
<tt>/usr/libexec/java_home</tt> returns returns the path to a Java home directory from the current user's settings.
<tt>/usr/libexec/java_home</tt> returns returns the path to a Java home directory from the current user's settings.


In case multiple JDKs are installed, the <tt>java_home</tt> command line variables can be used to filter which <tt>JAVA_HOME</tt> is returned. Also see "":
In case multiple JDKs are installed, the <tt>java_home</tt> command line variables can be used to filter which <tt>JAVA_HOME</tt> is returned. Also see "[[#Using_a_Specific_Java_Installation_when_Multiple_JDKs_are_Installed|Using a Specific Java Installation when Multiple JDKs are Installed]]":


-v filters on version
-v filters on version
Line 56: Line 60:
-d filters on data model.
-d filters on data model.


==Look for a Specific Version and Fail if Not Installed==
⚠️ On Big Sur, must unset JAVA_HOME before executing this command for the command to report the correct value:
<syntaxhighlight lang='bash'>
unset JAVA_HOME; /usr/libexec/java_home -F -v 11
</syntaxhighlight>
==Display all Java Installations on the System==
To see al JVMs installed:
To see al JVMs installed:


<pre>
<syntaxhighlight lang='bash'>
/usr/libexec/java_home -V
/usr/libexec/java_home -V
</pre>
</syntaxhighlight>


=Using a Specific Java Installation when Multiple JDKs are Installed=
=Using a Specific Java Installation when Multiple JDKs are Installed=
Line 69: Line 81:
  export PATH=${JAVA_HOME}/bin:${PATH}
  export PATH=${JAVA_HOME}/bin:${PATH}


=Default Java 1.6 Location=
=brew=
 
This is no longer valid since mid 2019, due to license changes. Update if needed.
 
<font color=darkgray>
brew install caskroom/cask/java
 
Install the latest, in the [[Java_Installation_on_Mac#Oracle_SDK_Installation|standard location]]. Everything specified in [[#Oracle_SDK_Installation|Oracle SDK Installation]] applies.
 
To install the latest of a specific major version:
 
  brew cask install caskroom/versions/java8
</font>
 
=Miscellanea=
 
==Default Java 1.6 Location==


<pre>
/Library/Java/Home/
/Library/Java/Home/
</pre>


If you want /usr/libexec/java_home to return the Java 6 home, run it with:
If you want /usr/libexec/java_home to return the Java 6 home, run it with:


<pre>
/usr/libexec/java_home -v 1.6
/usr/libexec/java_home -v 1.6
</pre>

Latest revision as of 19:54, 12 July 2021

Internal

Overview

By default, no Javs is installed, when first attempting to use I get this:

NOMBP2:~ ovidiu$ java -version
No Java runtime present, requesting install.

and a GUI window pops up: "to use the "java" command-line tool you need to install a JDK". More Info ... which says to go to the Oracle site.

Java Vendors

Oracle SDK Installation

Download the latest for Mac (jdk-9.0.1_osx-x64_bin.dmg, jdk-8u25-macosx-x64.dmg or jdk-7u75-macosx-x64.dmg, depending of whether you need Java 9, Java 8 or Java 7).

Double-click on DMG, then on PKG.

By default, it will install it in /usr/bin/java, which is a link to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java.

The default JAVA_HOME is:

/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/java
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

It can be obtained running

/usr/libexec/java_home

Amazon Corretto Installation

Amazon Corretto Installation on Mac

JAVA_HOME and /usr/libexec/java_home

For a standard installation the value of JAVA_HOME is returned by the result of /usr/libexec/java_home:


export JAVA_HOME=$(/usr/libexec/java_home)

...

export PATH=${JAVA_HOME}/bin:${PATH}

/usr/libexec/java_home returns returns the path to a Java home directory from the current user's settings.

In case multiple JDKs are installed, the java_home command line variables can be used to filter which JAVA_HOME is returned. Also see "Using a Specific Java Installation when Multiple JDKs are Installed":

-v filters on version

-a filters on architecture

-d filters on data model.

Look for a Specific Version and Fail if Not Installed

⚠️ On Big Sur, must unset JAVA_HOME before executing this command for the command to report the correct value:

unset JAVA_HOME; /usr/libexec/java_home -F -v 11

Display all Java Installations on the System

To see al JVMs installed:

/usr/libexec/java_home -V

Using a Specific Java Installation when Multiple JDKs are Installed

Set in .bashrc (the following command selects Java 8 when Java 7, 8 and 9 are installed):

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
export PATH=${JAVA_HOME}/bin:${PATH}

brew

This is no longer valid since mid 2019, due to license changes. Update if needed.

brew install caskroom/cask/java

Install the latest, in the standard location. Everything specified in Oracle SDK Installation applies.

To install the latest of a specific major version:

 brew cask install caskroom/versions/java8

Miscellanea

Default Java 1.6 Location

/Library/Java/Home/

If you want /usr/libexec/java_home to return the Java 6 home, run it with:

/usr/libexec/java_home -v 1.6