KnTq

Registered
Aug 3, 2019
4
0
1
EU
cPanel Access Level
Root Administrator
Hello,
I have a "Oversized" server for my DNS only installation so I use it also for other purposes. I wanted to install Elasticsearch which needs Java to run.

I installed Java using:

yum install java-1.8.0-openjdk-devel

It installs without problems but if I type:

java -version

I get this output:

-bash: java: command not found


I also tried to select Java version with:

update-alternatives --config java

and I get this output:

[[email protected] ~]# update-alternatives --config java
There is 1 program that provides 'java'.
Selection Command
-----------------------------------------------
*+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.
Enter to keep the current selection[+], or type selection number: 1
failed to link /usr/bin/java -> /etc/alternatives/java: /usr/bin/java exists and it is not a symlink
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,862
2,216
363
cPanel Access Level
DataCenter Provider
Twitter
Hello :)

Can you execute the following commands via SSH as root and share the output here?

Rich (BB code):
$ whmapi1 installed_versions packages=0|grep operating
$ rpm -qa|grep jdk
$ rpm -qa|grep java
Thank you.
 

KnTq

Registered
Aug 3, 2019
4
0
1
EU
cPanel Access Level
Root Administrator
Hello,

I have allready solved this problem.

First I renamed the folder /usr/bin/java

to /usr/bin/java-temp (or anything else....latter I also deleted it)

then
update-alternatives --config java

and it created the right symlink.

But there was also another problem which was solved with help of a support request so I will post it here if anyone does have the same problem.


Checking the "java" command using "which" shows the command being unable to be located:

# which java
/usr/bin/which: no java in (/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

Checking for the "java" binary in the default location returned the following:

# ls -lrt /usr/bin/java
lrwxrwxrwx. 1 root root 22 Aug 23 15:38 /usr/bin/java -> /etc/alternatives/java

# ls -lrt /etc/alternatives/java
lrwxrwxrwx. 1 root root 73 Aug 23 15:38 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre/bin/java

However, this file did not exist in the noted location. This broke the symlink and resulted in the command not functioning as expected:

# ls -lrt /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre/bin/java
ls: cannot access /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre/bin/java: No such file or directory

Using "rpm" and a "for loop" I checked for the file within the currently installed RPM packages for "java-1.8.0-openjdk":

# for i in $(rpm -qa | grep ^java\-1); do echo RPM: $i; rpm -ql $i | egrep java$; echo; done
RPM: java-1.8.0-openjdk-devel-1.8.0.222.b10-0.el7_6.x86_64
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/bin/java

RPM: java-1.8.0-openjdk-headless-1.8.0.222.b10-0.el7_6.x86_64
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre/bin/java

RPM: java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64

As the file was indeed locaated within "java-1.8.0-openjdk-headless-1.8.0.222.b10-0.el7_6.x86_64" I went ahead and reinstalled this RPM using "yum":

# yum reinstall java-1.8.0-openjdk-headless-1.8.0.222.b10-0.el7_6.x86_64

Installed:
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.222.b10-0.el7_6

Complete!

Now when checking for the file, running the "java -version" command, and checking for "java" using "which" all return as expected:

# ls -lrt /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre/bin/java
-rwxr-xr-x. 1 root root 7376 Jul 23 19:03 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre/bin/java

# java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

# which java
/usr/bin/java