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
  • 72,312
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,444
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,310
  • 2
  • 19
  • 24