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
- Go to Sun's website and get yourself a copy of the J2SE Development Kit. Get the .bin package, not the RPM.
- 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/javadirectory to contain all my JDKs and dropped the .bin package into there.
- Unpack it. Basically that means running
sh [package name].binand saying yes to the licensing stuff. It'll unpack itself into a new directory. Mine unpacked itself into
- 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.
- 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.
- 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 ..
- 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.
- Install the dummy packages:
dpkg -i *.deb. Now Debian knows that you've got Java installed.
- Still one more step to go... Now we'll use
update-alternativesto add in Debian-friendly symbolic links for all the utilities that come with Java. Change directories into the
bindirectory 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?
- Now you should be able to run
java -versionas any user and get back the correct version of the JDK you installed.
All done! Enjoy your snazzy new Java install.