Setting JDK 7 as default
[email protected]:~$ file /etc/alternatives/java /etc/alternatives/javac /etc/alternatives/java:symbolic link to `/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java' /etc/alternatives/javac:symbolic link to `/usr/lib/jvm/java-6-openjdk-amd64/bin/javac'
Forgive my noobishness but I am interpreting these messages as the runtime environment using Java 7 but the compiler is using Java 6?
Is this right, and if so, how can I set it to use Java version 7?
Switching between installed Java versions can be accomplished using the
To get a list of your installed Java platforms, run the following command from the terminal:
sudo update-alternatives --config java
This will give you a list output similar to this:
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-6-oracle/jre/bin/java 1070 auto mode 1 /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java 1051 manual mode * 2 /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java 1069 manual mode Press enter to keep the current choice[*], or type selection number:
In this case, the Open JDK 6 version is running. To switch to the Open JDK version 7, you would select option
1at the prompt and press the Enter key.
You will now be running the OpenJDK 7 version. No other changes will be needed to switch your Java versions.
@user142712 No problem. I believe that an uninstall would also remove the older browser plugin, which is beneficial security-wise.
I wouldn't go for the "No problem" answer so fast. Check http://www.oracle.com/technetwork/java/javase/compatibility-417013.html and http://upstream-tracker.org/java/versions/jdk.html. There is no 100% compatibility between those two major versions and it might happen so (unlikely but still...) that you have an application X that cannot run properly with the seventh version. Until you make sure there will be no issues I strongly advice to keep both just in case you need the previous version.
Just to be clear. The "no problem" comment was another way of me saying you are welcome, I never claimed that there would be no problems with your Java installation.
you need to do this for `javac` as well in case you wanna change the compiler as well.
The most voted answer which suggests to use
only partially answers the question. By using it you very likely to end up with your Java environment being inconsistent.
This is especially important if you have JDK, not JRE, as
[sudo] update-alternatives --config java
will change version for the the
javacommand only, i.e. repoint main JRE executable.
javacand other JDK tools will still point to the other java version. To fully switch you have to continue with
update-alternativesfor all other tools.
The proper and much easier way to switch Java versions in the Linux distribution with "alternatives" system - i.e. in the Debian or it's derivative Ubuntu - is to use update-java-alternatives command.
update-java-alternatives -l - will list installed Java versions
[sudo] update-java-alternatives -s - will switch to the requested version
You can run
sudo update-alternatives --config java, and select JDK 7, if it's installed.
Okay cheers, It says I have two of JKD7 installed one listing status as auto the other manual. Is there any difference?
There's Info here: http://linux.die.net/man/8/update-alternatives but i'd select auto.
"Each link group is, at any given time, in one of two modes: automatic or manual. When a group is in automatic mode, the alternatives system will automatically decide, as packages are installed and removed, whether and how to update the links. In manual mode, the alternatives system will not change the links; it will leave all the decisions to the system administrator. "
the GUI way
$ sudo apt-get install galternatives
$ sudo galternatives
more here: https://askubuntu.com/a/159594/216936