1

I stood up rhel VM. I was curious if JDK is installed or not so that I ran a command from a shell (bash).

whereis java

It returned:

java: /usr/bin/java

So I navigated to the path in order to verify Java program.

ls -l java

Which returned:

lrwxrwxrwx 1 root root 26 May 2016 10:52 java -> /usr/java/default/bin/java

so far so good however when ran java program:

java
-bash: java: command not found

It looks like java has symbolic link but /usr/java/default/bin/java is no longer exists. I just want to verify whether java (jdk) is installed or not but from what I've seen I am not too sure. I would like to believe that it is not installed if so why the system returned java: /usr/bin/java?

  • First: rpm -qa | grep jdk to search for other JDKs installed through package manager. Second, it may be missing a configured java alternative. You may need to configure java alternatives to deal with java, javac, javaws and other related to jdk - wiki.centos.org/HowTos/JavaRuntimeEnvironment – user34720 May 10 '16 at 17:20
2

I would like to believe that it is not installed if so why the system returned java: /usr/bin/java?

whereis doesn't resolve the symlink. So if /usr/bin/java still exist, even though the symlink target is broken, it will still return java: /usr/bin/java. I recommend you use type -a java to get the correct result. Please note that the symlink target OR non-symlink source file, both must be executable (chmod +x to set it), otherwise type -a command will return not found even though file exist (type will still return regardless of executable).

So, I can simplify like below:

whereis: Still return found even symlink broken or non-executable.

type: Return found even non-executable, and return not found if symlink broken.

type -a: Return not found when symlink is broken or non-executable.

All of them will return not found if the input file doesn't exist.

So, what I can advise is install the JDK again, which "Oracle JDK" is preferred over than "OpenJDK".

A good article can be found here.

This is what you can do (Assume your system are x64):

sudo rpm -ivh jdk-8u91-linux-x64.rpm
sudo rpm -ivh jdk-8u91-linux-x64-demos.rpm 

The version number of 8u91 version above is keep updating, so you should always visits Oracle websites to find out the latest version. Click the JDK DOWNLOAD button will go to this page which shows the latest version number and its correct filename.

You can also download the docs which the real link can be found here page, and unzip it (Assume your JDK has been installed at /usr/java/jdk1.8.0_91/):

sudo unzip jdk-8u91-docs-all.zip -d /usr/java/jdk1.8.0_91/ #optional

Then use this two commands to choose the correct javac and java. I believe you only have one option (This sample shows jdk1.8.0_74 due to mine is not the latest 8u91):

$ sudo alternatives --config javac

There are 2 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.fc21.x86_64/bin/javac
   2           /usr/java/jdk1.8.0_74/bin/javac

Enter to keep the current selection[+], or type selection number: 2
$
$ sudo alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.fc21.x86_64/jre/bin/java
 + 2           /usr/java/jdk1.8.0_74/jre/bin/java

Enter to keep the current selection[+], or type selection number: 2
$ 
  • Thank you for your kind explanation especially in regards to the first question I had. It turns out that jdk is missing and I re-installed it. – DaeYoung May 11 '16 at 14:12
1

You may have to configure Alternatives to point to java, its explained in my link.

I have noticed with trying to keep Oracle Java installed over the openjdk that you have to make sure everything is linking correct and running the correct version of java.

If using an RPM system machine, I used the steps in the link below for getting it to work.

Install Oracle Java JDK CentOS

The Java command below would work as a validation that the Alternatives have been setup correctly.

java -version

[root@somecomputer thebtm]# java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

Another side node is that if you already have Oracle Java installed and you download and install a newer java rpm, you have to update alternatives to point to the new version of java

[root@somecomputer thebtm]# alternatives --config java

There are 5 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.8.0_66/bin/java
   2           /usr/java/jdk1.8.0_66/jre/bin/java
   3           /usr/java/jre1.8.0_77/bin/java
   4           /usr/java/jdk1.8.0_77/jre/bin/java
 + 5           /usr/java/jre1.8.0_91/bin/java

Enter to keep the current selection[+], or type selection number: 5
[root@somecomputer thebtm]# java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.