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.
-
Trackback from Mini-HowTo: Installing Java on Debian Unstable on June 7, 2005 at 5:42 pm
-
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
-
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?
-
Trackback from Ulf Hjelmgren on July 19, 2005 at 9:56 am
-
Trackback from Annika Hjelmgren on July 19, 2005 at 9:56 am
-
A welcomed aid while installing a debian “sarge” JBoss development server. Nice clear instructions with in a compact concise format.
-
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 :-)
-
Excellent howto! Thank you very much!
-
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… -
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!
-
Hey, worked, thank you! What happens in case of updating the JDK to a newer version?
Cheers Morten
-
debian help visit this website http://www.debianhelp.co.uk
-
thanks mate!
-
x10 Thankz….
-
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
-
Thanks your howto is very helpfull, it works for me.
-
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!
-
Very good article. I installed according to this article, jdk1.6.0_03 on Debian 4.0
Thank You.
-
Very helpful thank you very much.
-
Pingback from Installing Red5 on Debian « Satria Online on November 18, 2008 at 12:36 am
-
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
-
Maybe someone is interested on java and jdob tutorial on debian: http://alexander.holbreich.org/2010/01/java-jboss-debian-linux/

30 comments
Comments feed for this article
Trackback link: http://chrismetcalf.net/blog/archives/2005/05/19/mini-howto-installing-java-on-debian-unstable/trackback/