JAVA_HOME environment variable and installed Java in CentOS - java

I am installing SUbversion Edge under CentOS 7.
The first step is
Set the JAVA_HOME environment variable, and point it to your Java 6 JRE
home. For example:
export JAVA_HOME=/usr/java/default
Test the variable:
$ $JAVA_HOME/bin/java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)
The problem is that /usr/java forlder not exists.
But /usr/bin/java is existing.
Have I use this folder instead?
So what do I have to do?

You should use correct Java home path in your system. If you installed Java in CentOS via YUM, then correct path should be
export JAVA_HOME=/usr/lib/jvm/jre
You should not use /usr/bin/java as JAVA_HOME, because it is not Java home path, it is symlink to java executable.

Related

Is PATH or Java_Home messed up?

I was able to install Java and SonarQube, configured the wrapper.conf, and adjusted the port to 9000 to make it work 3 days ago.
Now, running StartSonar.bat gave this
Unable to execute Java command. Access is denied. (0x5) wrapper |
"C:\Program Files\Java\jdk-11.0.11\bin" -Dsonar.wrapped=true ...
C:\Program Files\Java\jdk-11.0.11\bin is what I have in wrapper.conf and it did work.
In a cmd window, C:\windows\system32>java -version
java version "11.0.11" 2021-04-20 LTS Java(TM) SE Runtime Environment
18.9 (build 11.0.11+9-LTS-194) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode)
navigate to the path above do java -version reports the same.
However I noticed my system Path has this, verified the one in javapath is the same version.
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files(x86)\Common Files\Oracle\Java\javapath
And java_home is empty: echo %java_home% got %java_home%
I'm totally confused now. What went wrong?

Can't set JAVA_HOME dynamically on macOS Catalina

tl,dr;
Doing export JAVA_HOME=$(/usr/libexec/java_home -v 14) once JAVA_HOME was already set won't change active java
Steps
set JAVA_HOME first (for example with export JAVA_HOME=$(/usr/libexec/java_home -v 11)):
$ echo ${JAVA_HOME}
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
Try to set it to different version (for example export JAVA_HOME=$(/usr/libexec/java_home -v 14)) - it still uses previously set java (even though JAVA_HOME was updated):
$ echo ${JAVA_HOME}
/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home
$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
I'm not sure why it's not working now - it was working just fine a while back (I'd say 2-3 months ago)
There is a seemingly similar topic (Can't set JAVA_HOME on Catalina) but it boils down to different shell. In my case I'm using same shell - bash from brew:
$ bash -version
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Seems update JAVA_HOME is not getting reflected in PATH variable.
So, please update PATH variable also and keep the updated JAVA_HOME as the first element in the export PATH command
OK, I finally managed to solve the issue. As other have pointed out, everything has to do with PATH variable. And I indeed had JAVA_HOME/bin in thereā€¦ which causes the problem. Today during an update I notice that openjdk brew formula had this comment:
keg_only "it shadows the macOS `java` wrapper"
And things immediately "clicked". After searching a bit I found Why isn't java wrapper not picking up the right version specified in JAVA_HOME on macOS? which confirmed the issue. By including JAVA_HOME in the PATH in my .profile file I was breaking native macOS functionality of it's java wrapper, which selects active java version based on currently set JAVA_HOME.
This is my example session (from opening the shell and having export JAVA_HOME=$(/usr/libexec/java_home -v 11) in the .profile file) -- I have default from the profile, then I set explicitly JAVA_HOME and it switches java version on the fly:
$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
$ export JAVA_HOME=$(/usr/libexec/java_home -v 14)
$ java -version
openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.2+12)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.2+12, mixed mode, sharing)

Unable to find java executable. Check JAVA_HOME ... while starting Cassandra

Running Cassandra
$ apache-cassandra-3.11.1/bin/cassandra -f -R
Unable to find java executable. Check JAVA_HOME and PATH environment variables.
Java Settings are
java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (Zulu 8.20.0.5-linux64) (build 1.8.0_121-b15)
OpenJDK 64-Bit Server VM (Zulu 8.20.0.5-linux64) (build 25.121-b15, mixed mode)
whereis java
java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /data/ytbigdata/anaconda3/bin/java
which java
~/anaconda3/bin/java
~/.bash_profile setting
export JAVA_HOME=/data/ytbigdata/anaconda3/bin/java
export PATH=$JAVA_HOME/bin:$PATH
The Cassandra documentation says "On the Cassandra nodes where the agents are installed, create the file /etc/default/datastax-agent and set the environment variables for JAVA_HOME and any other custom environment variables that the agent might need." https://docs.datastax.com/en/opscenter/6.1/opsc/install/opscCustomVariables_t.html

Mac OS java home ambiguty

Please see these 3 commands and their outcomes in MacOS:
Korays-MacBook-Pro:~ koraytugay$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
Korays-MacBook-Pro:~ koraytugay$ java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
Korays-MacBook-Pro:~ koraytugay$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home
Why does the first one return 1.8? What exactly is /libexec/java_home ?
Koray,
As per the Oracle docs...
JAVA_HOME is just an environment variable used to trigger the 'java' found in your PATH to use a different JDK image. Unfortunately, not all 'java' startup scripts obey this env variable. It's also used by many java tool startup scripts to determine what 'java' to run, bypassing the 'java' found in the PATH setting. Setting this variable during a JDK build is a bad idea, don't do it.
I use Eclipse myself, and don't have a JAVA_HOME env variable defined, here is my output running the same commands.
brandon#brandons-mbp ~
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
brandon#brandons-mbp ~
$ java -version
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)
brandon#brandons-mbp ~
$ echo $JAVA_HOME
Not sure why you have two different versions but did you try updating your JDK recently? Maybe when you upgraded it failed to launch a script to update your $JAVA_HOME.
Here's the instructions for installing JDK and setting JAVA_HOME on *nix based OSes.
Let me know if that helps I can help you dig deeper if need be.

java -version different than expected

I'm having a problem with determining what version of java am I using:)
cmd.exe is using java.exe from C:\WINDOWS\system32 as specified in Path environment variable.
C:\WINDOWS\system32>java.exe -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode)
But in windows when I right-click on that file and select Properties->Version->Full Version it says 1.6.0_22-b04.
Why?
This means you have two installations. Check your c:\program files\Java folder. Also check your PATH environment variable - it should point to the correct path.
Change to a directory which is not in your PATH environment variable and run java -version. Note that the current directory always is the first entry in PATH.

Categories

Resources