using alternatives with java 7 and java 8 on 14.04.2 LTS

I had java 7 installed. Using the PPA repository, I added java 8.

sudo apt-get install oracle-java8-installer

That made java 8 the default. So, I tried to use update-alternatives to make java 7 the default.

sudo update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

That causes

java -version

to fail.

It looks as if the problem might be that there is a long list of alternatives for java, and I need to move them all around together. is there a way?


Because Java is made up of many programs, you'll want to use update-java-alternatives instead. Run update-java-alternatives -l to get a list of installed Java environments. Then, to set an environment as the default, run update-java-alternatives -s codename, where codename is the first part of the output.

For example, I have OpenJDK 7 and 8 installed. Here's the output for me:

07:52:36 ⌂134% θ70° [:~] $ update-java-alternatives -l
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64
07:54:36 ⌂105% θ70° [:~] 1 $ sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
[sudo] password for saikrishna: 
update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so

(Ignore the error at the end; IceaTea 8 isn't ready yet.)