In this example I am going to create a deb package for Java SE Development Kit 6 Update 31 using the dpkg-deb command.
dpkg-deb creates a debian archive from the filesystem tree stored in directory. directory must have a DEBIAN subdirectory, which contains the control information files such as the control file itself. This directory will not appear in the binary package's filesystem archive, but instead the files in it will be put in the binary package's control information area.
First lets download the JDK from Oracle and extract it:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@server1 ~] cd /usr/src | |
[root@server1 ~] wget http://download.oracle.com/otn-pub/java/jdk/6u31-b04/jdk-6u31-linux-x64.bin | |
[root@server1 ~] bash jdk-6u31-linux-x64.bin |
Since we are going to install JDK on Unutu, jdk-6u31-linux-x64 needs to go to /usr/lib/jvm, and the following symlinks needs to exist:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@server1 ~] ls -la /usr/bin/java | |
lrwxrwxrwx 1 root root 22 2012-02-17 19:24 /usr/bin/java -> /etc/alternatives/java | |
[root@server1 ~] ls -la /etc/alternatives/java | |
lrwxrwxrwx 1 root root 37 2012-02-17 19:24 /etc/alternatives/java -> /usr/lib/jvm/jdk1.6.0_31/jre/bin/java |
This means that our Debian package needs to extract the JDK distribution and create the symlinks (also remove them first if there's an older version of JDK already installed, as the symlinks will be pointing to it).
Lest create our packaging infrastructure:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@server1 ~] cd /usr/src | |
[root@server1 ~] mkdir -p sun-java6-jdk/usr/lib/jvm/ | |
[root@server1 ~] cp -rv /usr/src/jdk1.6.0_31/ sun-java6-jdk/usr/lib/jvm/ | |
[root@server1 ~] mkdir sun-java6-jdk/DEBIAN |
The DEBIAN directory will contain the two main files that tell dpkg-deb how to build the package and what scripts to execute if any:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@server1 ~] cat sun-java6-jdk/DEBIAN/control | |
Package: jdk-6u31-linux-x64 | |
Version: 1.6.0.31 | |
Priority: optional | |
Architecture: all | |
Maintainer: Your Name | |
Description: Oracle JDK 1.6.0_31 | |
[root@server1 ~] cat sun-java6-jdk/DEBIAN/postinst | |
#!/bin/bash | |
rm /usr/bin/java | |
rm /etc/alternatives/java | |
ln -s /usr/lib/jvm/jdk1.6.0_31/jre/bin/java /etc/alternatives/java | |
ln -s /etc/alternatives/java /usr/bin/java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@server1 ~] chmod 0755 sun-java6-jdk/DEBIAN/postinst |
Now that we have everything in place let's build the package:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@server1 ~] dpkg-deb --build sun-java6-jdk |
To install the package run:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@server1 ~] dpkg -i sun-java6-jdk.deb |
This will extract the files to /usr/lib/jvm, and create the symlinks specified in the postinst script.