2
votes

I am trying to install jre-7u51-linux-i586 in Ubuntu. The problem is after all installation, getting below Error:

$:/usr/local/java$ java -version

The program 'java' can be found in the following packages:

  • default-jre
  • gcj-4.6-jre-headless
  • openjdk-6-jre-headless
  • gcj-4.5-jre-headless
  • openjdk-7-jre-headless Try: sudo apt-get install

I have tried installing via webupd8, still same issue. Please help.

Thanks for the help you provided. Still I am at bay.

I am getting below error when I am trying to do update-alternatives:

$ sudo update-alternatives --remove "java" "/usr/lib/jvm/jdk1.7.0_25/bin/java" update-alternatives: warning: forcing reinstallation of alternative /usr/local/java/jre1.7.0_25/bin/java because link group java is broken. update-alternatives: warning: not replacing /usr/bin/java with a link.

Also I am getting below for the java versions installed. ~/Softwares$ sudo update-alternatives --display java java - manual mode link currently points to /usr/local/java/jre1.7.0_25/bin/java /usr/lib/jvm/jdk1.7.0_51/bin/java - priority 1 /usr/local/java/jre1.7.0_25/bin/java - priority 1 Current 'best' version is '/usr/lib/jvm/jdk1.7.0_51/bin/java'.

I have removed java as: sudo apt-get purge openjdk-* I am bit newbie in Linux, please help.

5
This question appears to be off-topic because it belongs to askubuntu.comSpringLearner
How did you install it - via synaptic or proper instalation? And where you install it?Thrash Bean

5 Answers

3
votes

I faced with the same problem in the near past and solved the issue in the following way.

Remove all possible JRE/JDK distributions from the hard drive and remove java alternatives from update-alternatives like that

  • First, list the possible alternatives

update-alternatives --config java

  • Second, remove all possibilities

update-alternatives --remove "java" "/usr/lib64/jvm/[jdkORjreVersion]/bin/java"

  • Third, extract the desired jre/jdk distribution the the desired path. (Note this path, we will use again)

  • Fourth, set JAVA_HOME and PATH variables like that

export JAVA_HOME=[installed jre/jdk path] export PATH=$PATH:[installed jre/jdk path/bin]

  • Set the installed java executable to the alternatives of java executables

update-alternatives --install "/usr/bin/java" "java" "[installed jre/jdk path]/bin/java" 1

update-alternatives --config java

  • Select the desired jre/jdk distribution.

PS: All these operations should be performed as a root.

1
votes

I think it's because before install, you have to delete the java that come with the operating system. you can use the following command: sudo apt-get purge openjdk-*

1
votes

After removing other distributions of java like openjdk, try installing oracle java using the installer or via webupd8. Then type the following two commands in the terminal.

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51  
export PATH=$PATH:$JAVA_HOME/bin

Now if you type java -version in the terminal, you should get the output printing the version of java runtime installed.

1
votes

Thanks all for their help.

I have done all, but was getting the same issue. I guess the issue was that each time java was getting installed, but could not determine which to execute as default. Finally after doing as told in @Girish's answer, I got this from ubuntu help pages:

sudo update-alternatives --config java

this will give you the java version u want to set and u can choose from 0,1,2 etc. Hope this helps.

0
votes

Verify avaialble installations in your machine : -

sudo update-alternatives --config java

There are 3 choices for the alternative java (providing /usr/bin/java).  


     Selection    Path                                     Priority   Status
    ------------------------------------------------------------
      0            /usr/lib/jvm/java-6-oracle/jre/bin/java   3         auto mode
    * 1            /usr/lib/jvm/java-6-oracle/jre/bin/java   3         manual mode
      2            /usr/lib/jvm/java-7-oracle/jre/bin/java   2         manual mode
      3            /usr/lib/jvm/java-8-oracle/jre/bin/java   1         manual mode

    Press <enter> to keep the current choice[*], or type selection number:

Now remove existing symbolic links first

sudo update-alternatives --remove "java" "/usr/lib/jvm/java-8-oracle/jre/bin/java" sudo update-alternatives --remove "java" "/usr/lib/jvm/java-7-oracle/jre/bin/java" sudo update-alternatives --remove "java" "/usr/lib/jvm/java-6-oracle/jre/bin/java"

-------javac

sudo update-alternatives --config javac
There are 3 choices for the alternative java (providing /usr/bin/javac).

  Selection    Path                                     Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-oracle/jre/bin/javac   3         auto mode
* 1            /usr/lib/jvm/java-6-oracle/jre/bin/javac   3         manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/javac  2         manual mode
  3            /usr/lib/jvm/java-8-oracle/jre/bin/javac  1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 

Now remove symbolic links

sudo update-alternatives --remove "javac" "/usr/lib/jvm/java-8-oracle/jre/bin/javac"
sudo update-alternatives --remove "javac" "/usr/lib/jvm/java-7-oracle/jre/bin/javac"
sudo update-alternatives --remove "javac" "/usr/lib/jvm/java-6-oracle/jre/bin/javac"

--if you see any issue with javaws than follow same steps to remvoe

Its time to set the symbolic links to your location, download the linux java version which you like and move the unziped directories to proper location like /usr/lib/jvm/ which common naming standard insted of one which you got from site name like java-6-oracle

sudo update-alternatives --set java /usr/lib/jvm/java-8-oracle/jre/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-8-oracle/jre/bin/javac
sudo update-alternatives --set javaws /usr/lib/jvm/java-8-oracle/jre/bin/javaws

Same like whichever the version you want just run above commands after placing in required location.

Change the jave version by using sudo update-alternatives --config java and selete the options.

leave the comment if any assistence required.