Chris Metcalf bio photo

Chris Metcalf

Twitter Facebook LinkedIn Instagram GitHub Stack Overflow Photography

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.