• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

location of java path in os X el capitan

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought I posted this topic, but maybe not, because I can't find it, so I'll ask it again just in case.  my apologies if it's still here somewhere.

I downloaded and installed Java 18 on my 11,6 iMac, 2010, quad core i7running el capitan.  I have a backlight issue, so I got an external monitor after a few years, and luckily I can still use the machine.  

However, when I entered java -version in the terminal, it says the default version is java 8.   I looked in the Library directory (/Library/Java/Java Virtual Machines) and sure enough the folder for Java 18 is there, but for some reason it isn't being 'seen' or chosen as the default java version.  in the past when I've installed java (like on my MB Pro just recently) in updated find and Java 18 is the default version.

I'm having to read up again on Unix, but I can't figure out where the necessary file/command -- whatever it is -- that determines the default Java version is.  it has to be somewhere, given the above statement.

Has anyone else had this problem, and can they offer any advice on how to fix this?   I simply want to make Java 18 the default version.
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the value of the JAVA_HOME variable? It should point to the JDK you want to use. You can find out its value on the command line via "echo $JAVA_HOME".
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Laurenzano wrote:I thought I posted this topic. . . .

Did you mean this thread?
 
Christopher Laurenzano
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell ...

I don't remember.   I did a search of all my posts and it didn't come up in any thread.   Perhaps I thought I did, but forgot to post.  That's all I meant.
 
Christopher Laurenzano
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim Moores --

There is no value for that.  I've been away from UNIX and the command line for a while, so I've been reading up on it.   I've also come across the java_home command, but when i enter that on the command line it says command not found.

I'm not clear on how to use the JAVA_HOME variable, and which file to put it in.

It's really weird, because I was able to install Java 18 on my MB pro -- but then again, I updated to High Sierra, and it's there when i enter java -version.  Yet on my iMac the Java 18 folder is there, in /Library/Java/Java Virtual machines/JDK 18.02 (installed the latest update, but again it only sees java 1.8 when java -version is entered at the command line.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you have those spaces in the path to Java18?
Please try all these instructions at a terminal on your machine that is misbehaving:-Please show us what they produce. I am not familiar with OS/X but other people are. If OS/X is a Unix type OS, it might be similar enough to the Linux box I am using that I might have some useful ideas.
 
Christopher Laurenzano
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell Ritchie --

No, the spaces were here in the post.  

Here are the results of your questions:

java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

javac -version
javac 1.8.0_112

echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

echo JAVA_HOME
(Blank Line)

And os x is UNIX, the BSD version.
 
Tim Moores
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Laurenzano wrote:
echo JAVA_HOME
(Blank Line)


I'm assuming you actually executed "echo $JAVA_HOME", because the results of "echo JAVA_HOME" would be "JAVA_HOME").

This is a problem - JAVA_HOME needs to point to your Java installation. On my machine that might be /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home (for the Adoptium OpenJDK 11), so the specifics might be different for you. But in any case, it points to a folder that contains bin, lib and jre subfolders, amongst others.

 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the sort of thing you should have seen:-

[campbell@localhost java]$ echo $JAVA_HOME
/usr/java/jdk-18

The path on your machine will be different. Please try the following instructions at a terminal (you probably have to escape the spaces):-Follow that with the two echo and two -version instructions and see what happens.
You appear neither to have set the JAVA_HOME nor the PATH variables.
Those above instructions will have effect only for the lifetime of the terminal window they were set from.
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Important Note:

JAVA_HOME is NOT an integral part of Java. It is a convention used by many, but by no means all Java application launch scripts to point to the desired JDK or JRE. If you just set JAVA_HOME and don't set something in the PATH, then more likely than not, no JVM will be found when you go to execute Java developer commands or Java apps.

It is a very commendable thing to set JAVA_HOME in your login profile script and to use it to augment your PATH (PATH=$JAVA_HOME/bin:$PATH) but there is no law requiring it. You never have to do either one of those things if you are working with software that doesn't mandate JAVA_HOME (in fact, I think it's optional for Tomcat) and you can always invoke JDK and JRE commands via their actual filesystem locations (ex: /usr/java/default/bin/java).

The key takeaway is that Java is not Internet (There Can Be Only One) Explorer. You can have a dozen different JDKs and JREs of varying versions and vendors splattered all over your filesystem. You can address a specific one within a specific shell instance by setting JAVA_HOME, but that won't affect any sibling shell instances, which might have set their own values of JAVA_HOME — or not. Nor will any commands that don't use the JAVA_HOME convention care what, if any, value you set JAVA_HOME to be.

Further, note that when setting the PATH with a reference to JAVA_HOME, that the value of the PATH will be set based on the value of JAVA_HOME when the path was set. If you later change JAVA_HOME, that won't update the PATH. You have to update the PATH separately.


A final note, probably Linux-specific. These days a lot of Linux distros come with OpenJDK pre-installed. The general practice has been to "linux-ize" the JDK installation. Meaning that the components are made to appear in stock Linux locations as defined by LSB, so you can find the Java compiler at /usr/bin/java for example. JAVA_HOME is not, however pre-defined in any of these distros that I know of, although you can define a JAVA_HOME; it's a little more subtle than the way you'd do if for the all-in-one-JDK-directory approach, though. Then there's the alternatives subsystem, which I'll forbear to comment on.
 
Christopher Laurenzano
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok , i just noticed something.  I went to my MB pro and entered

echo $JAVA_HOME and there's a blank line, yet when I enter

java -version

It comes up with Java 18, the latest version that I downloaded, so on this machine it properly set it, but on my iMac it didn't.

The MB pro is running High Sierra -- could that mean something?  
 
Tim Holloway
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Laurenzano wrote:Ok , i just noticed something.  I went to my MB pro and entered

echo $JAVA_HOME and there's a blank line, yet when I enter

java -version

It comes up with Java 18, the latest version that I downloaded, so on this machine it properly set it, but on my iMac it didn't.

The MB pro is running High Sierra -- could that mean something?  



Not a whole lot.

As I mentioned, in recent Linux releases, Java is installed in such a way that it appears to be a standard OS application(s) in the standard OS path (typically something like /usr/bin:/usr/local/bin, perhaps the sbin directories, whatever). Again, JAVA_HOME is not used by the OS to locate and execute Java. Only certain java product scripts reference that environment variable and use it as part of their internal path settings.

You can alway use the "which" command to see how the java executable was found when you typed in java -version.
 
Tim Holloway
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also let me clarify. I said recent Linux releases often pre-install OpenJDK, but that may be also true for recent MacOS releases. Sounds like it probably is.
 
Ranch Hand
Posts: 61
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I can't help with a general answer, but I can say where macOS 12 Monterey keeps its Java installation, at least up to Java 17. I asked my Eclipse preferences under "installed JREs" and it showed me.

Have a look at and its various sub-folders.

I do not know where it is if you do not install a JDK but only a Java runtime environment.

Good luck
Peter

 
Peter Schuster
Ranch Hand
Posts: 61
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Schuster wrote:
I do not know where it is if you do not install a JDK but only a Java runtime environment.



Just an addition. This link might help: https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-macos.htm.

Now I faintly remember that macOS treats the JRE still as an browser plug-in. I you did not find the JRE in your Library, search: for a . If it is a symbolic link, have a look where it takes you using cmd+i.

I hope that helped.

Regards peter
 
Christopher Laurenzano
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something interesting --

I went to the oracle website and was able to download and install every version of java up to and including 16.  I thought maybe i was so out of date that this might help.   But when I downloaded and installed java 17 and 18 both it didn't find it when I enter the command java -version.

The command

which java -version

yields the result

/usr/bin.

I'm still at a loss as to what's going on.

I downloaded java 18 from Oracle.  It's the SE development kit, it has everything.  It's the same thing i've done with previous versions.
 
Tim Holloway
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Some more corrections/clarifications.

Eclipse can have one or more JDK's installed for the use of compiling and running Eclipse projects. There may be other JDKs installed that were never registered in Eclipse and for that matter, you can have registered a JDK in Eclipse, deleted the JDK and Eclipse won't realize it - keep showing the JDK as "installed" even through there's nothing actually there to use.

I believe that the current Eclipse installers look for a pre-installed JDK to run Eclipse itself under. Note that a JDK "installed in" Eclipse is used for project work is not the same thing as the JDK that Eclipse (which is a Java app itself) runs under. So the JDK that runs Eclipse may or may not show up in Eclipse's "installed JDK's" dialog list.

In short, Eclipse isn't the definitive place to determine where your "official" JDK lives.

Note also that Oracle JDKs (and JREs) are NOT the same thing as OpenJDK. Although Oracle is involved in the OpenJDK project and Oracle is the final certifier for any Java distribution, even if the actual JDK is IBM's J9 system, downloading/installing Oracle JDKs isn't the same thing as downloading/installing OpenJDK.

Most often OpenJDK comes from your distro repository. Presumably wherever Apple keeps Brew packages for MacOS. Not from oracle/sun.com.

The standard Oracle/Sun JDK or JRE package simply downloads as a ZIP file. You unzip it to any location that's convenient to you - even your home directory if you like. There are also special install packages for Windows and Red Hat-style Linux, but they're all based ultimately on the JDK itself being a simple directory tree.

While you can install Oracle JDKs by downloading/unzipping the raw archives, the Red Hat OS also has a package in RPM (RedHat Package Manager) format. It installs JDKs as sub-directories under /usr/java and also maintains a softlink (/usr/java/latest) to the most recent installed JDK.

If the Java runtime is located at /usr/bin you are almost certainly dealing with an OS-managed copy of OpenJDK. As I said, JAVA_HOME is a little tricky for that configuration. I believe you simply set it to "/" (the system root directory).

And again, JAVA_HOME has no magic itself. Only apps written to use JAVA_HOME care whether or not JAVA_HOME is defined or where it points.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Laurenzano wrote:. . . which java -version . . .

That is a different instruction from what I showed you.
 
Christopher Laurenzano
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell -- I'm unfamiliar with the which command.  Could you show me how to use it in this context?  

Tom Holloway --

I don't quite understand.  I'm not using an IDE -- I just use TextMate for now.   I've always downloaded the JDK from Oracle's site, and i've had no problems before this.  The download on the Oracle site is a .dmg file.  I've always just downloaded it and installed it with no problem.


Campbell -- update.  I looked up the command in the man pages, but i'm on my linux machine right now.  But I assume you mean

which -a java

am I correct?
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Laurenzano wrote:. . . the which command.  Could you show me how to use it in this context?  

The which command tells you what the path is to what happens when you call the program following. I suspect it has ignored the second argument (-version). You don't need it in this context. Use java ‑version.

. . . I assume you mean

which -a java

am I correct?

Afraid not. That will list the paths to all the different locations where the java command might be found. Again not what I wanted.
 
Tim Holloway
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Laurenzano wrote:Campbell -- I'm unfamiliar with the which command.  Could you show me how to use it in this context?  

Tom Holloway --

I don't quite understand.  I'm not using an IDE -- I just use TextMate for now.   I've always downloaded the JDK from Oracle's site, and i've had no problems before this.  The download on the Oracle site is a .dmg file.  I've always just downloaded it and installed it with no problem.


Campbell -- update.  I looked up the command in the man pages, but i'm on my linux machine right now.  But I assume you mean

which -a java

am I correct?



The IDE stuff was in response to others attempting to help by telling you where you could find Java in the Eclipse IDE. I wanted to point out that that wasn't the best place to find your "real" Java. If you're not using an IDE, of course, their advice was even less useful.

To find the location of an executable from Unix command line, no fancy options are required. Just type the command "which java" and it will return the location of the program (or script) that the shell would execute if you typed in the command "java" at a command prompt.

Again, let me emphasize that if you have the OpenJDK package installed in your OS, then downloading and installing an Oracle JDK won't make much difference. You'd have the software, but by default (as indicated by the "which" command) you'd be executing OpenJDK not Oracle JDK. To run the Java tools in the Oracle JDK you'd have to determine where Oracle installed it (or where you'd unzipped it if you downloaded the ZIP version) and add that location's bin directory to your PATH. That would make subsequent. For example, adding "/usr/java/jdk-11.0.13/bin" to your PATH would make "which java" return "/usr/java/jdk-11.0.13/bin/java". Assuming that you'd installed that particular JDK release in that particular location.

Again, manually changing the PATH only works for the current shell instance.  To make that JDK your default always, you'd need to set up the PATH in a login profile script.
 
Danger, 10,000 volts, very electic .... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic