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/opt/java/jdk1.5.0_03. - Create a symbolic link from the unpacked JDK directory to
/usr/local/lib/jdk. For me, that meant running the commandln -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 commandcp /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 thebindirectory 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.

28 comments
Comments feed for this article
Trackback link
http://chrismetcalf.net/blog/archives/2005/05/19/mini-howto-installing-java-on-debian-unstable/trackback/
June 7, 2005 at 5:42 pm
Trackback from Mini-HowTo: Installing Java on Debian Unstable - Mini-HowTo: Installing Java on Debian Unstable
July 4, 2005 at 11:01 am
Pingback from chrismetcalf.net - blog » Debian: Integrating applications installed in /opt using Debian “alternatives”
July 19, 2005 at 9:56 am
Trackback from Ulf Hjelmgren - Mini-HowTo: Installing Java on Debian Unstable
July 19, 2005 at 9:56 am
Trackback from Annika Hjelmgren - Mini-HowTo: Installing Java on Debian Unstable
April 15, 2007 at 4:50 am
Trackback from hulk.osd.wednet.edu/~hoangdq/Website/stat/in200/naked-asian-cams.html - naked asian cams...
November 7, 2008 at 3:28 am
Pingback from Red5 auf S4U Eco Big (openSuse 10.2) Hilfe gesucht - Server Support Forum
November 18, 2008 at 12:36 am
Pingback from Installing Red5 on Debian « Satria Online
July 1, 2005 at 7:20 pm
Gernot Hassenpflug
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
July 9, 2005 at 5:38 pm
Sandip Bhattacharya
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?
August 4, 2005 at 10:47 am
Dan Williamson
A welcomed aid while installing a debian “sarge” JBoss development server. Nice clear instructions with in a compact concise format.
August 4, 2005 at 3:02 pm
Mark Davidson
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 :-)
August 8, 2005 at 5:52 pm
Daniel Engler
Excellent howto! Thank you very much!
August 17, 2005 at 2:35 am
Ben
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…September 5, 2005 at 6:09 pm
Aldo
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!
September 27, 2005 at 5:55 am
Skagen Watch
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.
October 14, 2005 at 12:58 pm
Morten
Hey, worked, thank you! What happens in case of updating the JDK to a newer version?
Cheers Morten
December 7, 2005 at 4:42 am
sher
debian help visit this website http://www.debianhelp.co.uk
July 23, 2006 at 3:17 pm
preben
thanks mate!
February 3, 2007 at 8:25 am
Stelios_g
x10 Thankz….
May 4, 2007 at 7:54 pm
chazim
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
May 25, 2007 at 3:15 pm
HP
Thanks! This did the trick on Debian Sarge and Java 1.6 (latest version) also!
June 20, 2007 at 3:16 pm
vleyzphpob
Hello! Good Site! Thanks you! bpcpxzkwkxxvf
August 1, 2007 at 8:41 pm
Reynaldo
Thanks your howto is very helpfull, it works for me.
August 28, 2007 at 4:58 pm
Andrew
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!
October 7, 2007 at 2:08 am
Robert Weg
Very good article. I installed according to this article, jdk1.6.0_03 on Debian 4.0
Thank You.
December 3, 2007 at 2:31 pm
john morden
Very helpful thank you very much.
March 15, 2008 at 12:51 am
Bill
June 17, 2008 at 9:55 am
wuigho lcinb
yexu gznsflht vanwy ycrmaz lvbgzk degsw phyxlaqui