java command in centos 7

General support questions
Post Reply
mahmood
Posts: 36
Joined: 2017/06/04 12:21:09

java command in centos 7

Post by mahmood » 2018/04/24 12:29:15

Although I have installed openjdk package, the java command is not available. I see similar questions about centos 7, however, I wonder why the solution is not systematically provided and the executable path isn't added to $PATH.

Code: Select all

[root@rocks7 ~]# java
bash: java: command not found...
[root@rocks7 ~]# find /usr/ -name java
/usr/include/google/protobuf/compiler/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/java
/usr/lib/jvm/java
/usr/lib/jvm-exports/java
/usr/lib/java
/usr/share/swig/2.0.10/java
/usr/share/java
[root@rocks7 ~]# yum list java-1.8.0-openjdk*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.coreix.net
 * epel: kartolo.sby.datautama.net.id
Installed Packages
java-1.8.0-openjdk.x86_64                                 1:1.8.0.151-1.b12.el7_4             @anaconda/7.0
java-1.8.0-openjdk-devel.x86_64                           1:1.8.0.151-1.b12.el7_4             @Rocks-7.0
java-1.8.0-openjdk-headless.x86_64                        1:1.8.0.151-1.b12.el7_4             @anaconda/7.0
Available Packages
java-1.8.0-openjdk.i686                                   1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-accessibility.i686                     1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-accessibility.x86_64                   1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-accessibility-debug.i686               1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-accessibility-debug.x86_64             1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-debug.i686                             1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-debug.x86_64                           1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-demo.i686                              1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-demo.x86_64                            1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-demo-debug.i686                        1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-demo-debug.x86_64                      1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-devel.i686                             1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-devel-debug.i686                       1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-devel-debug.x86_64                     1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-headless.i686                          1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-headless-debug.i686                    1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-headless-debug.x86_64                  1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-javadoc.noarch                         1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-javadoc-debug.noarch                   1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-javadoc-zip.noarch                     1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-javadoc-zip-debug.noarch               1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-src.i686                               1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-src.x86_64                             1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-src-debug.i686                         1:1.8.0.151-1.b12.el7_4             Rocks-7.0
java-1.8.0-openjdk-src-debug.x86_64                       1:1.8.0.151-1.b12.el7_4             Rocks-7.0

MartinR
Posts: 329
Joined: 2015/05/11 07:53:27
Location: UK

Re: java command in centos 7

Post by MartinR » 2018/04/24 13:59:55

You need openjdk-headless which will install it and set up /usr/bin/java as a link into /etc/alternatives which goes to the actual binary.

mahmood
Posts: 36
Joined: 2017/06/04 12:21:09

Re: java command in centos 7

Post by mahmood » 2018/04/24 14:08:59

As you can see, the headless has been installed.

User avatar
TrevorH
Forum Moderator
Posts: 23213
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: java command in centos 7

Post by TrevorH » 2018/04/24 14:16:46

You've either done something to your PATH so that it's not found or you've used alternatives to point to a different java. Just running yum install java is enough to download and install java-1.8.0-openjdk.x86_64 which supplies a /bin/java command. I'd suggest yum reinstall java
CentOS 5 died in March 2017 - migrate NOW!
Full time Geek, part time moderator. Use the FAQ Luke

mahmood
Posts: 36
Joined: 2017/06/04 12:21:09

Re: java command in centos 7

Post by mahmood » 2018/04/24 14:41:59

Reinstall wasn't helpful

Code: Select all

[root@rocks7 ~]# yum reinstall java
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.coreix.net
 * epel: mirrors.sohu.com
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.151-1.b12.el7_4 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package                      Arch             Version                           Repository           Size
===========================================================================================================
Reinstalling:
 java-1.8.0-openjdk           x86_64           1:1.8.0.151-1.b12.el7_4           Rocks-7.0           241 k

Transaction Summary
===========================================================================================================
Reinstall  1 Package

Total download size: 241 k
Installed size: 501 k
Is this ok [y/d/N]: y
Downloading packages:
java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.rpm                                 | 241 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64                                       1/1
  Verifying  : 1:java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64                                       1/1

Installed:
  java-1.8.0-openjdk.x86_64 1:1.8.0.151-1.b12.el7_4

Complete!
[root@rocks7 ~]# java
bash: java: command not found...
[root@rocks7 ~]# echo $PATH
/opt/openmpi/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/ganglia/bin:/opt/ganglia/sbin:/opt/rocks/bin:/opt/rocks/sbin:/root/bin
[root@rocks7 ~]#

User avatar
TrevorH
Forum Moderator
Posts: 23213
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: java command in centos 7

Post by TrevorH » 2018/04/24 14:57:51

/opt/openmpi/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/ganglia/bin:/opt/ganglia/sbin:/opt/rocks/bin:/opt/rocks/sbin:/root/bin
And you still have the symlinks for /sbin and /bin to their /usr/{bin,sbin} equivalents? What does alternatives --display java say?
CentOS 5 died in March 2017 - migrate NOW!
Full time Geek, part time moderator. Use the FAQ Luke

mahmood
Posts: 36
Joined: 2017/06/04 12:21:09

Re: java command in centos 7

Post by mahmood » 2018/04/24 15:04:34

Code: Select all

[root@rocks7 ~]# alternatives --display java
java - status is auto.
 link currently points to /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/java - family java-1.8.0-openjdk.x86_64 priority 1800151
 slave jre: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre
 slave jre_exports: /usr/lib/jvm-exports/jre-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64
 slave jjs: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/jjs
 slave keytool: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/keytool
 slave orbd: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/orbd
 slave pack200: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/pack200
 slave rmid: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/rmid
 slave rmiregistry: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/rmiregistry
 slave servertool: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/servertool
 slave tnameserv: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/tnameserv
 slave policytool: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/policytool
 slave unpack200: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/unpack200
 slave java.1.gz: /usr/share/man/man1/java-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave jjs.1.gz: /usr/share/man/man1/jjs-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave keytool.1.gz: /usr/share/man/man1/keytool-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave orbd.1.gz: /usr/share/man/man1/orbd-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave pack200.1.gz: /usr/share/man/man1/pack200-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave rmid.1.gz: /usr/share/man/man1/rmid-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave rmiregistry.1.gz: /usr/share/man/man1/rmiregistry-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave servertool.1.gz: /usr/share/man/man1/servertool-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave tnameserv.1.gz: /usr/share/man/man1/tnameserv-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave policytool.1.gz: /usr/share/man/man1/policytool-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
 slave unpack200.1.gz: /usr/share/man/man1/unpack200-java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64.1.gz
Current `best' version is /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre/bin/java.

Post Reply