Mini-HowTo: Installing Java on Debian Unstable

Every time I set up a new system I have to figure out how to do this again, so I decided to post instructions for my benefit and for the benefit of those who might also be having problems with this.

Debian’s “Social Contract” forbids it from distributing “non-free” code as official packages. Thus, Sun’s version of Java is not in any of the official mirrors. You can sometimes find third-party packages from Blackdown and other groups, but they are often out of date and annoying. I prefer to get my Java directly from Sun.

I install my JDKs into /opt and use “dummy packages” to let Debian know that I really do have Java installed. That way I can install Debian packages requiring Java to be installed and everything will go smoothly.

This mini-HowTo assumes that you’re running Debian Unstable (Sid), but it should also work if you’re using Testing or even Ubuntu. It also assumes you’re doing all these steps as root.

Installing Sun’s Java on Debian Unstable

  1. Go to Sun’s website and get yourself a copy of the J2SE Development Kit. Get the .bin package, not the RPM.
  2. Put it wherever you want to finally reside. I put all apps that don’t come from Debian packages into /opt, so I created a /opt/java directory to contain all my JDKs and dropped the .bin package into there.
  3. Unpack it. Basically that means running sh [package name].bin and saying yes to the licensing stuff. It’ll unpack itself into a new directory. Mine unpacked itself into /opt/java/jdk1.5.0_03.
  4. Create a symbolic link from the unpacked JDK directory to /usr/local/lib/jdk. For me, that meant running the command ln -s /opt/java/jdk1.5.0_03 /usr/local/lib/jdk.
  5. Install the java-common and equivs packages by calling apt-get install java-common equivs. These packages will be used to create the dummy packages.
  6. Into a suitable temporary directory (I was in /opt/java), copy the Java dummy package control files, using the command cp /usr/share/doc/java-common/dummy-packages/*.control ..
  7. Use equivs to create the dummy packages from the control files: for fn in *.control; do equivs-build $fn; done. You’ll end up with a bunch of .deb’s in your working directory.
  8. Install the dummy packages: dpkg -i *.deb. Now Debian knows that you’ve got Java installed.
  9. Still one more step to go… Now we’ll use update-alternatives to add in Debian-friendly symbolic links for all the utilities that come with Java. Change directories into the bin directory of your installed JDK (cd /opt/java/jdk1.5.0_03/bin) and run the following command: for fn in *; do update-alternatives --verbose --install /usr/bin/$fn $fn /usr/local/lib/jdk/bin/$fn 500 --slave /usr/share/man/man1/$fn.1 $fn.1 /usr/local/lib/jdk/man/man1/$fn.1; done. This loop will create Debian “alternatives” for all the utilities that came with your JDK package, along with links for their man pages. Neat, eh?
  10. Now you should be able to run java -version as any user and get back the correct version of the JDK you installed.

All done! Enjoy your snazzy new Java install.

Tags: , , ,

  1. Gernot Hassenpflug’s avatar

    Your page is really helpful, I saw it after checking a variety of other links, and yours is much more clearly understandable. Thank you! I am not sure if this is necessary, but for example on http://hurring.com/howto/java/debian_install/ the following lines are used to set up environment variables after installing java as you have explained:

    export JDK_HOME=/usr/local/lib/jdk export CLASSPATH=$JDK_HOME export PATH=”$PATH:${JDK_HOME}/bin:${JDK_HOME}/jre/bin”

    I hope this is helpful to others who access your page (feel free to edit the comment…)

    Ciao, Gernot

  2. Sandip Bhattacharya’s avatar

    I dont see the point of creating the symlink to /usr/local/lib/jdk. If we use the original /opt path of jdk while running update-alternatives, we can repeat this process for additional versions of java that we might use in the future. That way, we can use Debian’s alternative system to switch all the programs over to a different version of java at the same time, isn’t it?

  3. Dan Williamson’s avatar

    A welcomed aid while installing a debian “sarge” JBoss development server. Nice clear instructions with in a compact concise format.

  4. Mark Davidson’s avatar

    Thanks for the clear instructions! Although I’m relatively new to Debian you’ve made it easy for me to get JDK 1.5 up and running. Right – I’m off to install Eclipse now :-)

  5. Daniel Engler’s avatar

    Excellent howto! Thank you very much!

  6. Ben’s avatar

    For comment #2 (I am not sure if this is necessary): It is not necessary to modify your PATH (try “$> ls -l which java“). Magical…

  7. Aldo’s avatar

    great howto! it solved my need to install the jdk of sun on my debian box: this is the only procedure that worked for me. thank you again!

  8. Skagen Watch’s avatar

    I’ve just been staying at home not getting anything done. I haven’t been up to much recently. My life’s been really bland recently. I’ve basically been doing nothing worth mentioning. I just don’t have much to say lately.

  9. Morten’s avatar

    Hey, worked, thank you! What happens in case of updating the JDK to a newer version?

    Cheers Morten

  10. preben’s avatar

    thanks mate!

  11. Stelios_g’s avatar

    x10 Thankz….

  12. chazim’s avatar

    The final instruction “java -version”, returns the version, so, I guess this works on ETCH too. I’m still a somewhat newby. I wish more linux instructions were this easy to follow, and worked out this well. thanks charlie

  13. HP’s avatar

    Thanks! This did the trick on Debian Sarge and Java 1.6 (latest version) also!

  14. vleyzphpob’s avatar

    Hello! Good Site! Thanks you! bpcpxzkwkxxvf

  15. Reynaldo’s avatar

    Thanks your howto is very helpfull, it works for me.

  16. Andrew’s avatar

    Extremely informative and helpful. I especially like that you give at least general terms for what each step does, not just a list of (to a *nix newb, at least) unfamiliar commands to execute.

    Thanks!

  17. Robert Weg’s avatar

    Very good article. I installed according to this article, jdk1.6.0_03 on Debian 4.0

    Thank You.

  18. john morden’s avatar

    Very helpful thank you very much.

  19. wuigho lcinb’s avatar

    yexu gznsflht vanwy ycrmaz lvbgzk degsw phyxlaqui

  20. kenneth’s avatar

    I have i problem. I get this error message sh java_ee_sdk-5_01-linux.bin java_ee_sdk-5_01-linux.bin: java_ee_sdk-5_01-linux.bin: cannot execute binary file

  21. shuron’s avatar

    Maybe someone is interested on java and jdob tutorial on debian: http://alexander.holbreich.org/2010/01/java-jboss-debian-linux/