Ubuntu seems to favour OpenJDK/JRE very much over Sun JDK/JRE. Even after I installed Sun JRE, JDK and plugin and spent some time plucking out OpenJDK-related packages, apt-get has installed them back with some packages as a dependency. Can this behaviour be corrected in favour of Sun Java packages? I'd like to have one and only Java stack installed (yes, it's a bit of OCD, but I like to have my systems clean) and want it to be Sun Java.
Update: as Marcos Roriz notes, the problem seems to be in default-jre (on which Java-dependent packages use to depend) pointing to OpenJDK, so the question seems to go about how to hack default-jre/default-jdk to point to Sun Java.
Installing Sun Java on Older Versions of Ubuntu (9.10 and below)
I had the same problem once about three years ago with Ubuntu 8.04 I think. There was a weird problem when using openjre and the problem was solved by using the sun jre version. Here are the steps in the terminal which apply to versions below 10.04, since starting from 10.04 sun java has been dropped and replaced by openjre:
(Everything Sun java related. Just to make sure)
After that, if you removed openjdk then you would only have sun java. If you did not remove it then you have both of them. To change from one to another do this:
sudo update-java-alternatives -l
- This will show you the list of java engines you can use.The name of the java alternative is the one in the left so for example openjdk would appear like this:
And you would set the system to openjdk like this:
If you would want to use Sun then you would do this (After installation of the sun packages):
If you want to use the java 7 version, simply change the number 6 mentioned above for 7. For example if I wanted to install the openjre version 7 I would:
Installing Sun Java on Newer versions of Ubuntu (10.04 an above)
Open the terminal and type the following:
That should install the Sun Java version on your system. To change to it simply do the following in case you have other java alternatives:
If you want the installation to be automatic type the following:
after that simply do the following to set the default environment variables:
Note that the PPA includes versions 6, 7 and 8. So you can install any of them by simply changing the number in the installation line, for example:
Would install Java 8. After installing the Java version you wish to use and setting the version to the default with the
update-java-alternatives
command, you can check which version you are using by typing the following:It will show you the default version you are using at that moment.
I would like to also mention that OpenJRE/JDK has come a long way from 2 or 3 years ago when it had many issues that were solved by changing to Sun Java.
I think the problem is that some Java packages rely on default-jre which points to openjdk-jre. I don't think there is a easy way to permanetely uninstall openjdk. The thing is that you probably will bump on openjdk again when you install a java package/program.
But if you're willing to have both, is it easy to set the java runtime programs (java, javah, javap, and so on) to sun implementation. Do it:
or if you are a java dev (install the sdk and srcs):
And set it as the default programs with:
The
.jdk1.6.0_23.jinfo
file should be a list of the supplied programs and their paths. There is a descriptive header followed by a blank line. Then a list of the programs in a three field format: entry type (jre/jkd/plugin); program name; and path. You should have some jinfo files you can use to see what the contents should look like. This is likely used by the alternatives mechanism to determine which links to create. The head of my Sun package is.If you want to override the default Java commands without using the alternatives mechanism put your Java path ahead of /usr/bin in your path.
When doing a manual install, I install Java in
/opt
. for your install I would have installed in/opt/jdk1.6.0_23
. Then I put the path$JAVA_HOME/bin
at the start of myPATH
variable.EDIT: This is the whole Sun file. Note
.java-6-sun.jinfo
is a symbolic link to.java-6-sun-1.6.0.22.jinfo
.Delete openjdk and icedtea:
add the following to /etc/apt/sources.list
install Sun/Oracle JRE or JDK:
Did you check it?
If you don't need it: Deinstall openjdk and gcj in synaptic or with apt-get.
I would ban java from alternatives then, and do mostly as BillThor suggested, why I gave him an upvote.
should point to where you installed java, and where it is found in the PATH.
java -version
in shell (it will display Sun java only)sudo update-java-alternatives -l
and it works only if you have two jdk installed and you wanna set sun-java as a default environment
The thing I do on new Ubuntu 10.10 machines is
Then it is fine for me, no more openJDK dependencies
Using Ubuntu 10.10,it seems you need to mark for removal libaccess-bridge-java first in Synaptic, and then mark openjdk-6-jre-headless.
I ended up with a list to be removed:
This worked but it left a directory
/etc/java-6-openjdk
behind with assorted files and subdirectories within, which I isolated in a new directory. There have been no unusual effects, so presumably it is just a leftover remnant.This left me with the Java I had downloaded directly from the Java website. However, despite having set it as default and creating the link to the Firefox plugins directory, it no longer worked. Installing sun-java6-jre and it's associated packages gsfonts-x11, odbcinst, odbcinst1debian2, sun-java6-bin, and unixodbc, via Synaptic, saw the Java plugin begin working again. Removing the link in the plugins directory and replacing it with the actual libnpjp2.so file did not work. Using a link to the libjavaplugin_oji.so files in either the ns7 or ns7-gcc29 directories in the Java installed through Synaptic did not work either. This suggests to me that to get the latest Java plugin in Firefox one can follow the instructions on the Java website, and that the integrated Linux Java of whichever variety is present is needed to run the downloaded Java, which then relies for it's operation on the files surrounding it once the plugin has been activated. While a full understanding of the code comprising Java and Linux would be required to really solve it's mysteries, perhaps these experiments are helpful in finding the reasons why two Java's may be needed in this case. At least it is possible to remove all Java as well, if anyone finds it useful to do so.
The answers given to this question did not work for me. That is, the following failed:
With the error:
Try these instructions, instead:
icedtea-6-jre-cacao
), if it is installed.The OpenJDK (IcedTea) is now installed, which should allow you (if you had this error) to continue installing Oracle's JDK without error.
See also:
First: remove openjdk and icedtea plugin.
Second: copy the .bin jdk file to /opt or /usr/java and extract it.
Third: put a link of the java file to /usr/bin/
update the alternatives using update-alternatives
Create a symbolic link to the Java Plugin in the Firefox plugins directory.
Create a symbolic link to the Java Plugin libnpjp2.so file in the Firefox plugins directory:
Hope this helps.