4

I can't install Java 7. I selected it as advised, but nothing changes when I type java -version.

when I type sudo update-alternatives --config java I get:

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

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java 1075        auto mode
  1            /usr/lib/jvm/java-7-oracle/jre/bin/java 1074        manual mode

when I type 1 and then enter and then run java -version I find that my choice has not been effective.

java

Zanna
  • 70,465
lyly
  • 103

2 Answers2

6

Use this command:

$ sudo update-alternatives --config java

You'll get a result similar to:

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

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-oracle/jre/bin/java          1093      auto mode
  1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/lib/jvm/java-8-oracle/jre/bin/java          1093      manual mode
  3            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      manual mode

Answer the prompt for the version you wish to run.


You can remove the versions that don't work then ensure a good install of the one you want to use:

Look at: Problem changing Java version using alternatives

    The user in the accepted answer in the link resolved this problem by removing ALL the installed java versions and installing the ones he wanted to use. After this the `sudo update-alternatives --config java` command worked.

After you have removed the problem versions, you can install the version you want to run with:

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo install oracle-jdk7-installer
L. D. James
  • 25,036
  • I already tried that I chose for example 1 then installs but when I type java -version nothing chnage – lyly Aug 31 '16 at 23:43
  • @lyly Can you update your question with the text that you have in your image. I can't make out the exact response. If it were in text I could use Google's translator to better decipher the error response. – L. D. James Sep 01 '16 at 00:06
  • I followed the same guy you told me to install java 8 but still the old version remained – lyly Sep 01 '16 at 00:13
  • @lyly Try first selecting 0 and 2 and see if it changes. Make sure (which I understand that you're doing) that you use the elevated sudo prefix to your command. – L. D. James Sep 01 '16 at 00:15
  • I have already had my teacher has to prblm rrivé to change the version with a method that I forgot that she parcque chnage not and I do not remember how he blocked ss I do I have switched this version please help me james – lyly Sep 01 '16 at 00:18
  • @lyly Try apt-get remove to remove the unwanted versions. During this might resolve also resolve the update-alternatives problem. – L. D. James Sep 01 '16 at 00:25
  • @james james please I Tappe sudo apt-get remove java6 me or what I want parcque java8 installed and before I have java 6 – lyly Sep 01 '16 at 00:32
  • @james you are here – lyly Sep 01 '16 at 00:39
  • @lyly I'm trying to move this extended comment session to chat. Give me a moment to research. – L. D. James Sep 01 '16 at 00:43
  • @lyly In the meantime you can use apt-cache search to find the package names of the other java versions and use sudo apt-get remove them by name. – L. D. James Sep 01 '16 at 00:44
  • @lyly One type search to remove the version 6, try: apt-cache search java.*6.*oracle. Then remove the packages from the search result. – L. D. James Sep 01 '16 at 00:46
  • james sorry I insisted I just tried what you say but my m displays no command – lyly Sep 01 '16 at 00:53
  • update-java-alternatives should be used so that associated programs like javap are updated as well. – Olathe Sep 01 '16 at 00:58
  • @lyly Can you type in the exact command you typed that gave you the no command error? – L. D. James Sep 01 '16 at 01:00
  • thanx james youra are my best I succeeded – lyly Sep 01 '16 at 01:01
  • @lyly You're welcome. Consider placing a check mark with the answer since this helped. – L. D. James Sep 01 '16 at 01:04
  • you're the one who helped me merci james – lyly Sep 01 '16 at 01:07
  • @lyly Glad it worked. – L. D. James Sep 01 '16 at 01:08
  • @james jet same problem Java 6 has been removed I have Tappe sudo update-alternatives --config java I board selected 1 to 8 java then when I type java -version No such file or dirctory – lyly Sep 01 '16 at 01:13
  • @lyly What is the output of the sudo update-alternatives --config java. Add the text to your question. – L. D. James Sep 01 '16 at 01:15
  • sudo update-java-alternatives -l – lyly Sep 01 '16 at 01:22
  • java-7-oracle 1074 /user/lib/jvm/java-7-oracle – lyly Sep 01 '16 at 01:23
  • java-8-oracle 1075 /user/lib/jvm/java-8-oracle – lyly Sep 01 '16 at 01:24
  • @lyly What is the full output you get when you type in sudo update-alternatives --config java Paste the full output to a message. – L. D. James Sep 01 '16 at 01:25
  • a typed sudo update-java-alternatives -s java-7-oracle – lyly Sep 01 '16 at 01:25
  • @lyly I don't know if you're saying the alternative method is working. If you are still having problems, I'll need to see the output of the command I gave you. Are you still having problems? – L. D. James Sep 01 '16 at 01:27
  • sorry when I type sudo update-alternatives --config java there are two choices for the alternative java (which provides / user / bin / java) selction the way state priority 0 / user / lib / jvm / java-8-oracle / jre / bin / java 1075 automatic / User / lib / jvm / java-7-oracle / jre / bin / java 1074 manual / User / lib / jvm / java-8-oracle / jre / bin / java 10755 manual – lyly Sep 01 '16 at 01:31
  • @lyly Ok. So the next step is to install the version that you want to run. I'll add the command for the installation to my answer. Give me a couple minutes to format it easy to read. – L. D. James Sep 01 '16 at 01:33
  • @lyly Which version of Ubuntu are you running? 16.04? – L. D. James Sep 01 '16 at 01:35
  • @james no 14.04 – lyly Sep 01 '16 at 01:35
  • @lyly Look at the last 4 lines of my answer. – L. D. James Sep 01 '16 at 01:39
  • @james I do not see anything – lyly Sep 01 '16 at 01:41
  • @james you are her – lyly Sep 01 '16 at 01:45
  • @lyly Are you looking at the answer just below your question? You'll see my avatar which is a yellow and read box. – L. D. James Sep 01 '16 at 01:45
  • @jmaes I installed java java 8 and 7 my problem I can not get the sélctionné you understand me – lyly Sep 01 '16 at 01:49
  • @lyly The same way I edited my answer. Will you edit your question? Run this command: sudo update-alternatives --config java Copy and paste what you get in the terminal screen to your question. So that I can see the exact output. This is similar to the original picture that you posted. Paste it to your question. – L. D. James Sep 01 '16 at 01:54
  • when I type sudo update-alternatives --config java there are two choices for the alternative java (which provides / user / bin / java) selction the way state priority 0 / user / lib / jvm / java-8-oracle / jre / bin / java 1075 automatic / User / lib / jvm / java-7-oracle / jre / bin / java 1074 manual / User / lib / jvm / java-8-oracle / jre / bin / java 10755 manual – lyly Sep 01 '16 at 01:57
  • when I type sudo update-alternatives --config java there are two choices for the alternative java (which provides / user / bin / java) selction the way state priority 0 / user / lib / jvm / java-8-oracle / jre / bin / java 1075 automatic / User / lib / jvm / java-7-oracle / jre / bin / java 1074 manual / User / lib / jvm / java-8-oracle / jre / bin / java 10755 manual – lyly Sep 01 '16 at 01:57
  • I can't make out the text in the comment. This what you just pasted here, click on edit to where you typed your original question. Paste it there. It'll make it easy for me to read and see what teh problem is. I believe it'll take just minutes after I can see this text in your question. – L. D. James Sep 01 '16 at 01:59
  • @lyly If you can't copy and paste the text. Paste another image and I'll see what is happening from there. – L. D. James Sep 01 '16 at 02:01
  • @lyly I will be able to see from the text which java is selected, or I will be able to understand what error is happening if I can see the exact text that comes on your screen when you type in the command. – L. D. James Sep 01 '16 at 02:04
  • @james I modified you can see the – lyly Sep 01 '16 at 02:07
  • @lyly What you put there is something that you typed. Look at what is in my answer how the output looks. Did you use the copy and paste command so that you could have the output exactly the way it was on your screen? What I'm looking at won't work. – L. D. James Sep 01 '16 at 02:13
  • @lyly Also, I believe there is a problem with your Java installation. I was hoping to look at the exact output to help identify the problem. But if you would remove versions 7 and 8, then use the command I gave you in the answer (as well as in the link I provided), I'm sure the problem would be resolved. I would hope to see the exact output so that I can see where the * is on the your screen. – L. D. James Sep 01 '16 at 02:15
  • @james thanx for helping me I abandon I unable – lyly Sep 01 '16 at 02:16
  • @james I have posted another question with the same problem you may please see – lyly Sep 01 '16 at 02:29
  • @I would recommend that you not post a duplicate question with the same problem. That is strictly against the rules. There already are two answers to your question here. You have to be patient and sometimes wait a day or so for the best answer. – L. D. James Sep 01 '16 at 02:31
  • @JAMES VOUS AVEZ VU MA PUBLICATION – lyly Sep 01 '16 at 02:37
  • @lyly Yes. I didn't down-vote your question, but I knew it would be down-voted because as I mentioned, duplicating questions is strictly against the rules. I adding formatting to my answer that might make it easier for you to follow. I added clarification to make it ease for others having a similar problem. I believe there was something wrong with your original installation. – L. D. James Sep 01 '16 at 02:58
  • @james hello you are here I found no answer for my publication please help me – lyly Sep 01 '16 at 12:33
  • @lyly Did you remove all the java versions as indicated in the answer? – L. D. James Sep 01 '16 at 12:35
  • @james not because I know which version is supported scala I want to try java7 with scala 2.11.6 if it works I will not use java 8 below for that I want kept the two versions – lyly Sep 01 '16 at 12:39
  • Comments are not for extended discussion; this conversation has been moved to chat. – jokerdino Sep 01 '16 at 12:41
  • @lyly Look at my response at: http://chat.stackexchange.com/rooms/44789/discussion-on-answer-by-l-d-james-how-can-i-select-a-certain-version-of-java – L. D. James Sep 01 '16 at 12:47
  • @L.D.James I posted a question you can view please – lyly Sep 02 '16 at 00:03
0

To switch between installed JDKs

  1. List Java alternatives:

    update-java-alternatives -l
    
  2. Find the line with the Java you want.

  3. Remember the first part of the line. For example, Oracle Java 8's line might look like this on your system:

    java-8-oracle                  1082       /usr/lib/jvm/java-8-oracle
    

    The first part of the line there is java-8-oracle.

  4. Set the first part of the line you want as the Java alternative (replace java-8-oracle with the Java you want):

    sudo update-java-alternatives -s java-8-oracle
    
Olathe
  • 4,240
  • when I type sudo update-java-alternatives -s java-7-oracle nothing changes I should do please – lyly Sep 01 '16 at 01:53