49

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.

1
  • please any one update the answer with oracle jdk..
    – LoveToCode
    Aug 10, 2016 at 10:03

10 Answers 10

35

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:

sudo apt-get remove openjdk-6-jre default-jre default-jre-headless

sudo apt-get install sun-java6-jre sun-java6-bin sun-java6-plugin sun-java6-fonts

(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:

java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk

And you would set the system to openjdk like this:

sudo update-java-alternatives -s java-6-openjdk

If you would want to use Sun then you would do this (After installation of the sun packages):

sudo update-java-alternatives -s java-6-sun

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:

sudo apt-get install openjdk-7-jre default-jre default-jre-headless

Installing Sun Java on Newer versions of Ubuntu (10.04 an above)

Open the terminal and type the following:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update   
sudo apt-get upgrade   
sudo apt-get install oracle-java7-installer

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:

sudo update-java-alternatives -s java-7-oracle  

If you want the installation to be automatic type the following:

sudo echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections

after that simply do the following to set the default environment variables:

sudo apt-get install oracle-java7-set-default

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:

sudo apt-get install oracle-java8-installer

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:

java -version

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.

0
11

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:

sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

or if you are a java dev (install the sdk and srcs):

sudo apt-get install sun-java6-jdk sun-java6-jre sun-java6-source

And set it as the default programs with:

sudo update-java-alternatives -s java-6-sun
2
  • 1
    Yes, I believe this is about default-jre. No, I really don't want to have both Sun and Open JDKs - this is what's the question about - to have one and only and let it be Sun JDK. Is there a way to hack default-jre to point to Sun JRE?
    – Ivan
    Jan 12, 2011 at 0:05
  • Yep, I'll try to rebuild the default-jre package to point to sun-java this evening. Right now I'm @ work. Jan 12, 2011 at 11:46
6

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.

name=java-6-sun-1.6.0.22
alias=java-6-sun
priority=63
section=non-free

jre ControlPanel /usr/lib/jvm/java-6-sun/jre/bin/ControlPanel
jre java /usr/lib/jvm/java-6-sun/jre/bin/java
jre java_vm /usr/lib/jvm/java-6-sun/jre/bin/java_vm

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 my PATH 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.

name=java-6-sun-1.6.0.22
alias=java-6-sun
priority=63
section=non-free

jre ControlPanel /usr/lib/jvm/java-6-sun/jre/bin/ControlPanel
jre java /usr/lib/jvm/java-6-sun/jre/bin/java
jre java_vm /usr/lib/jvm/java-6-sun/jre/bin/java_vm
jre javaws /usr/lib/jvm/java-6-sun/jre/bin/javaws
jre jcontrol /usr/lib/jvm/java-6-sun/jre/bin/jcontrol
jre keytool /usr/lib/jvm/java-6-sun/jre/bin/keytool
jre pack200 /usr/lib/jvm/java-6-sun/jre/bin/pack200
jre policytool /usr/lib/jvm/java-6-sun/jre/bin/policytool
jre rmid /usr/lib/jvm/java-6-sun/jre/bin/rmid
jre rmiregistry /usr/lib/jvm/java-6-sun/jre/bin/rmiregistry
jre unpack200 /usr/lib/jvm/java-6-sun/jre/bin/unpack200
jre orbd /usr/lib/jvm/java-6-sun/jre/bin/orbd
jre servertool /usr/lib/jvm/java-6-sun/jre/bin/servertool
jre tnameserv /usr/lib/jvm/java-6-sun/jre/bin/tnameserv
jre jexec /usr/lib/jvm/java-6-sun/jre/lib/jexec
jdk HtmlConverter /usr/lib/jvm/java-6-sun/bin/HtmlConverter
jdk appletviewer /usr/lib/jvm/java-6-sun/bin/appletviewer
jdk apt /usr/lib/jvm/java-6-sun/bin/apt
jdk extcheck /usr/lib/jvm/java-6-sun/bin/extcheck
jdk idlj /usr/lib/jvm/java-6-sun/bin/idlj
jdk jar /usr/lib/jvm/java-6-sun/bin/jar
jdk jarsigner /usr/lib/jvm/java-6-sun/bin/jarsigner
jdk javac /usr/lib/jvm/java-6-sun/bin/javac
jdk javadoc /usr/lib/jvm/java-6-sun/bin/javadoc
jdk javah /usr/lib/jvm/java-6-sun/bin/javah
jdk javap /usr/lib/jvm/java-6-sun/bin/javap
jdk jconsole /usr/lib/jvm/java-6-sun/bin/jconsole
jdk jdb /usr/lib/jvm/java-6-sun/bin/jdb
jdk jhat /usr/lib/jvm/java-6-sun/bin/jhat
jdk jinfo /usr/lib/jvm/java-6-sun/bin/jinfo
jdk jmap /usr/lib/jvm/java-6-sun/bin/jmap
jdk jps /usr/lib/jvm/java-6-sun/bin/jps
jdk jrunscript /usr/lib/jvm/java-6-sun/bin/jrunscript
jdk jsadebugd /usr/lib/jvm/java-6-sun/bin/jsadebugd
jdk jstack /usr/lib/jvm/java-6-sun/bin/jstack
jdk jstat /usr/lib/jvm/java-6-sun/bin/jstat
jdk jstatd /usr/lib/jvm/java-6-sun/bin/jstatd
jdk native2ascii /usr/lib/jvm/java-6-sun/bin/native2ascii
jdk rmic /usr/lib/jvm/java-6-sun/bin/rmic
jdk schemagen /usr/lib/jvm/java-6-sun/bin/schemagen
jdk serialver /usr/lib/jvm/java-6-sun/bin/serialver
jdk wsgen /usr/lib/jvm/java-6-sun/bin/wsgen
jdk wsimport /usr/lib/jvm/java-6-sun/bin/wsimport
jdk xjc /usr/lib/jvm/java-6-sun/bin/xjc
plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so
plugin mozilla-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so
2
  • I don't have any java installed so I don't have anything related to it, nothing installed, no .jinfo files etc. I created the usr/lib/jvm folder myself because I read that that's where it's installed by default, and I'm going to keep it that way. That's why I would like to see the full content of the .jinfo file for the Sun's JDK.
    – jurchiks
    Feb 13, 2011 at 11:18
  • I've added the full sun .jinfo file.
    – BillThor
    Feb 13, 2011 at 15:58
6

Delete openjdk and icedtea:

apt-get purge openjdk-\* icedtea-\* icedtea6-\*

add the following to /etc/apt/sources.list

deb http://ppa.launchpad.net/webupd8team/java/ubuntu YOUR_UBUNTU_VERSION_HERE main

install Sun/Oracle JRE or JDK:

apt-get install oracle-jdk7-installer
apt-get install oracle-java7-installer 
1
  • 2
    And after this you are left with no Java at all... The question actually refers to who to replace one with the other, not how to remove OpenJDK from your system. Add a bit more information to your answer, the question cannot be answered only by following these steps. Apr 18, 2012 at 15:25
4

I added this line to the /etc/environment file: JAVA_HOME="/usr/lib/jvm/jdk1.6.0_23" and added JAVA_HOME/bin to the PATH variable, BUT the OS still doesn't recognise the command java, says it's not installed and offers me gcj and openjdk.

Did you check it?

echo $JAVA_HOME 
echo $PATH

If you don't need it: Deinstall openjdk and gcj in synaptic or with apt-get.

apt-get remove gcj 
apt-get remove openjdk

I would ban java from alternatives then, and do mostly as BillThor suggested, why I gave him an upvote.

which javac
which java

should point to where you installed java, and where it is found in the PATH.

12
  • I don't have gcj or openjdk installed... Just tried the which commands and it prints nothing. Found out that I forgot the $ symbol before the JAVA_HOME variable in PATH, I'll restart now and see how it goes.
    – jurchiks
    Feb 13, 2011 at 11:19
  • Restarted the PC, but the which command still shows nothing. Both JAVA_HOME and PATH variables are correct: echo $JAVA_HOME /usr/lib/jvm/jdk1.6.0_23 echo $PATH $JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games Where could be the problem? Edit: GOD DAMN IT, why are there no line breaks in comments??
    – jurchiks
    Feb 13, 2011 at 11:53
  • a) restarting the PC shouldn't be required. Reopen the shell should suffice, or mostly relogin as user. b) Look inside the help for formatting in comments. I see echo $PATH $JAVA_HOME/bin:/usr/local/sbin... but in the result $JAVA_HOME must be evaluated - there is something wrong, or your reporting is mistakable. c) Linebreaks: They aren't there, so that we constantly hit ENTER too early, and then the clock ticks, because editing is just for few minutes allowed - I constantly step into that trap. I hate it! :) Feb 13, 2011 at 12:38
  • Well, the JAVA_HOME variable is in the same file (/etc/environment), just in the first line. Maybe it should be somewhere else? It recognises it when I type echo $JAVA_HOME though...
    – jurchiks
    Feb 13, 2011 at 14:16
  • My question was: Does echo $PATH print $JAVA_HOME... or does it print the value for JAVA_HOME, i.e.: /usr/lib/jvm/jdk1.6.0_23 ? Feb 14, 2011 at 0:37
3
  1. Open System->Administration-> Synaptic Package Manager and then remove OpenJDK completely.
  2. Test version of Java typing java -version in shell (it will display Sun java only)
  3. Type sudo update-java-alternatives -l
  4. you are done. Now you have only sun java installed and it's setup as default jdk

and it works only if you have two jdk installed and you wanna set sun-java as a default environment

2

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:

ca-certificates-java, icedtea-6-jre-cacao, libaccess-bridge-java, libaccess-bridge-java-jni, openjdk-6-jre, openjdk-6-jre-headless,openjdk-6-jre-lib.

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.

2

The thing I do on new Ubuntu 10.10 machines is

  • add java-6-sun,
  • remove openJDK (add sun Java first otherwise a bunch of things will be removed like tomcat, etc)

Then it is fine for me, no more openJDK dependencies

1
  • java-6-sun isn't it the ubuntu-default-package, or is it? May 20, 2012 at 15:18
2

The answers given to this question did not work for me. That is, the following failed:

sudo apt-get purge sun-java5-jre sun-java6-font sun-java6-jre

With the error:

Virtual packages like 'sun-java6-jre' can't be removed

Try these instructions, instead:

  1. Open Ubuntu Software Centre.
  2. Search for IcedTea.
  3. Remove IcedTea Java Plug-in (icedtea-6-jre-cacao), if it is installed.
  4. Select OpenJDK Java 7 Runtime.
  5. Click Install.
  6. Wait for the 41.6 MB package to download and install.

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:

1

First: remove openjdk and icedtea plugin.

sudo apt-get remove openjdk* icedtea*

Second: copy the .bin jdk file to /opt or /usr/java and extract it.

sudo cp jdk_1.16.0.bin /usr/java

Third: put a link of the java file to /usr/bin/

ln -s /usr/java/jdk_1.6.0/bin/java /usr/bin/java
ln -s /usr/java/jdk_1.6.0/bin/javac /usr/bin/javac

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:

   cd  

<Firefox>/plugins


 ln -s  

<JRE>/lib/i386/libnpjp2.so .

Hope this helps.

2
  • Didn't you miss a step after cp, and before linking? And: You suggest manual linking, but there are 45 files in java/bin, most of them executable. Would you like to make 25 symbolic links? I would prefer changing the PATH. Feb 13, 2011 at 7:48
  • as far as i know the steps are correct. you can refer to the tutorial on sun(oracle's) java installation page. the above steps worked for me though!. let me know how you get along.
    – Ubuntuser
    Feb 14, 2011 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .