0

I have installed java the same was as following steps on another similar CentOS Linux release 7.3.1611 and its working fine. On this machine I ran the same steps as follow

1. wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz"
2. tar -xvzf jdk-8u121-linux-x64.tar.gz
3. alternatives --install /usr/bin/java java /usr/local/jdk1.8.0_121/java 2
4. alternatives --config java
5. alternatives --install /usr/bin/javac javac /usr/local/jdk1.8.0_121/bin/javac 2
6. alternatives --set javac /usr/local/jdk1.8.0_121/bin/javac
7. export PATH=$PATH:/usr/local/jdk1.8.0_121/bin:/usr/local/jdk1.8.0_121/jre/bin

So each time when I ran this steps again then I the java -version works. After some times it becomes the same command not found.

What is my mistake?

  • what does echo $PATH show when you see a "command not found" message? – thrig Jun 13 '17 at 13:41
  • @thrig its showing /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin – user8012596 Jun 13 '17 at 13:43
  • @thrig when I run this echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/jdk1.8.0_121/bin:/usr/local/jdk1.8.0_121/jre/bin I notice the java -version is working back? – user8012596 Jun 13 '17 at 13:46
  • Sounds like you need to set that PATH modification in your shell configuration, e.g. .bashrc or .bash_profile to make it stick around. – thrig Jun 13 '17 at 13:46
  • @thrig why is it ok on my other machine? Ok what command should I run to make sure it stick? – user8012596 Jun 13 '17 at 13:50
0

You had a typo in line 3 of your question. Left out the '/bin/' in '/usr/local/jdk1.8.0_121/java' in the alternatives command. Should have been '/usr/local/jdk1.8.0_121/bin/java'.

alternatives --install /usr/bin/java java /usr/local/jdk1.8.0_121/bin/java 180121

Extra information: When I install Java this way, I also make some of the ancillary programs slaves in the alternatives command. For the priority, I make a string from the Java release number. You can get by with just the single line command, but I would have used something similar to the following:

alternatives --install /usr/bin/java java \
   /usr/local/jdk1.8.0_121/bin/java 180121 \
   --slave /usr/bin/jar jar /usr/local/jdk1.8.0_121/bin/jar \
   --slave /usr/bin/jarsigner jarsigner /usr/local/jdk1.8.0_121/bin/jarsigner \
   --slave /usr/bin/javac javac /usr/local/jdk1.8.0_121/bin/javac \
   --slave /usr/bin/javadoc javadoc /usr/local/jdk1.8.0_121/bin/javadoc \
   --slave /usr/bin/javah javah /usr/local/jdk1.8.0_121/bin/javah \
   --slave /usr/bin/javap javap /usr/local/jdk1.8.0_121/bin/javap \
   --slave /usr/bin/javaws javaws /usr/local/jdk1.8.0_121/bin/javaws \
   --slave /usr/bin/jconsole jconsole /usr/local/jdk1.8.0_121/bin/jconsole \
   --slave /usr/bin/jcontrol jcontrol /usr/local/jdk1.8.0_121/bin/jcontrol \
   --slave /usr/bin/jdb jdb /usr/local/jdk1.8.0_121/bin/jdb \
   --slave /usr/bin/jhat jhat /usr/local/jdk1.8.0_121/bin/jhat \
   --slave /usr/bin/jinfo jinfo /usr/local/jdk1.8.0_121/bin/jinfo \
   --slave /usr/bin/jmap jmap /usr/local/jdk1.8.0_121/bin/jmap \
   --slave /usr/bin/jps jps /usr/local/jdk1.8.0_121/bin/jps \
   --slave /usr/bin/jrunscript jrunscript /usr/local/jdk1.8.0_121/bin/jrunscript \
   --slave /usr/bin/jsadebugd jsadebugd /usr/local/jdk1.8.0_121/bin/jsadebugd \
   --slave /usr/bin/jstack jstack /usr/local/jdk1.8.0_121/bin/jstack \
   --slave /usr/bin/jstat jstat /usr/local/jdk1.8.0_121/bin/jstat \
   --slave /usr/bin/jstatd jstatd /usr/local/jdk1.8.0_121/bin/jstatd \
   --slave /usr/bin/jvisualvm jvisualvm /usr/local/jdk1.8.0_121/bin/jvisualvm
  • I dont get you When I install Java this way, I also make some of the ancillary programs slaves in the alternatives command. For the priority, I make a string from the Java release number. You can get by with just the single line command, but I would have used something similar to the following:? – user8012596 Jun 14 '17 at 9:28
  • It bundles all the Java commands. So if you wanted to remove the alternative, alternatives --remove java /usr/local/jdk1.8.0_121/bin/java will remove all the links for the other 1.8.0_121 programs (javac, javadoc, etc). – Deathgrip Jun 14 '17 at 9:32
  • normally I use is java and javac only. Do I need to include all then ? – user8012596 Jun 14 '17 at 9:37
  • I notice you use this 180121 the bigger number is better or smaller? – user8012596 Jun 14 '17 at 9:38
  • A higher priority will be the one in use automatically. You can manually override, but if I need a specific version I use the fully qualified paths to where I unpacked the tarball. I create the priority from the Java release. 1.8.0_121 becomes 180121. When I install the next update (8u131 for example), the priority will be 180131. Since it's higher, it becomes the default version. – Deathgrip Jun 14 '17 at 9:44

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.