Create deb Package in Ubuntu (Very Brief Introduction)

This is a very brief and basic introduction to creating a deb package. It’s more of a log /history of commands I ran (while learning this myself) and their output. Special thanks to How To Create A .DEB Package [Ubuntu / Debian] for serving as the base I used to build this post. Log in to your Ubuntu machine and open a terminal. Then run the following commands.

cg@codeghar:~$ mkdir custom-package

cg@codeghar:~$ cd custom-package/

cg@codeghar:~/custom-package$ pwd

/home/cg/custom-package

cg@codeghar:~/custom-package$ mkdir credner-1.0

cg@codeghar:~/custom-package$ cd ~/source/

cg@codeghar:~/source$ ls

credner-1.0.tar.gz  credner.py

cg@codeghar:~/source$ vim credner.py

#!/usr/bin/env python3
print ("Hello World!")

cg@codeghar:~/source$ cp credner-1.0.tar.gz ~/custom-package/

cg@codeghar:~/source$ cd -

/home/cg/custom-package

cg@codeghar:~/custom-package$ ls

credner-1.0  credner-1.0.tar.gz

cg@codeghar:~/custom-package$ sudo aptitude install build-essential autoconf automake autotools-dev dh-make debhelper devscripts fakeroot xutils lintian pbuilder

Note: All these packages will be installed as required.

cg@codeghar:~/custom-package$ ls

credner-1.0  credner-1.0.tar.gz

cg@codeghar:~/custom-package$ cd credner-1.0/

cg@codeghar:~/custom-package/credner-1.0$ ls

cg@codeghar:~/custom-package/credner-1.0$ dh_make -e credner@example.com -f ../credner-1.0.tar.gz

Type of package: single binary, indep binary, multiple binary, library, kernel module, kernel patch?
 [s/i/m/l/k/n] s

Maintainer name  : codeghar
Email-Address    : credner@example.com
Date             : Wed, 14 Nov 2012 16:02:15 -0800
Package Name     : credner
Version          : 1.0
License          : blank
Type of Package  : Single
Hit  to confirm:
Currently there is no top level Makefile. This may require additional tuning.
Done. Please edit the files in the debian/ subdirectory now. You should also
check that the credner Makefiles install into $DESTDIR and not in / .

cg@codeghar:~/custom-package/credner-1.0$ ls

debian

cg@codeghar:~/custom-package/credner-1.0$ cd debian/

cg@codeghar:~/custom-package/credner-1.0/debian$ ls

changelog          credner.default.ex   emacsen-startup.ex  menu.ex      README.Debian
compat             credner.doc-base.EX  init.d.ex           postinst.ex  README.source
control            docs                 manpage.1.ex        postrm.ex    rules
copyright          emacsen-install.ex   manpage.sgml.ex     preinst.ex   source
credner.cron.d.ex  emacsen-remove.ex    manpage.xml.ex      prerm.ex     watch.ex

cg@codeghar:~/custom-package/credner-1.0/debian$ vim control

Source: credner
Section: unknown
Priority: extra
Maintainer: codeghar 
Build-Depends: debhelper (>= 8.0.0)
Standards-Version: 3.9.2
Homepage: 
#Vcs-Git: git://git.debian.org/collab-maint/credner.git
#Vcs-Browser: http://git.debian.org/?p=collab-maint/credner.git;a=summary

Package: credner
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: First test deb package
 This is my first deb package attempt

cg@codeghar:~/custom-package/credner-1.0/debian$ vim copyright

Format: http://dep.debian.net/deps/dep5
Upstream-Name: credner
Source: 

Files: *
Copyright: 2012 codeghar 
License: GPL-2+
 This package is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 .
 This package is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 .
 You should have received a copy of the GNU General Public License
 along with this program. If not, see 
 .
 On Debian systems, the complete text of the GNU General
 Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".

# If you want to use GPL v2 or later for the /debian/* files use
# the following clauses, or change it to suit. Delete these two lines
Files: debian/*
Copyright: 2012 codeghar 
License: GPL-2+
 This package is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 .
 This package is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 .
 You should have received a copy of the GNU General Public License
 along with this program. If not, see 
 .
 On Debian systems, the complete text of the GNU General
 Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".

# Please also look if there are files or directories which have a
# different copyright/license attached and list them here.

cg@codeghar:~/custom-package/credner-1.0/debian$ vim changelog

credner (1.0-1) unstable; urgency=low

  * Initial release (Closes: #nnnn)  

 -- codeghar   Wed, 14 Nov 2012 16:02:15 -0800

cg@codeghar:~/custom-package/credner-1.0/debian$ cd ..

cg@codeghar:~/custom-package/credner-1.0$ dpkg-buildpackage -us -uc -rfakeroot

dpkg-buildpackage: export CFLAGS from dpkg-buildflags (origin: vendor): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security
dpkg-buildpackage: export CPPFLAGS from dpkg-buildflags (origin: vendor): -D_FORTIFY_SOURCE=2
dpkg-buildpackage: export CXXFLAGS from dpkg-buildflags (origin: vendor): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security
dpkg-buildpackage: export FFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export LDFLAGS from dpkg-buildflags (origin: vendor): -Wl,-Bsymbolic-functions -Wl,-z,relro
dpkg-buildpackage: source package credner
dpkg-buildpackage: source version 1.0-1
dpkg-buildpackage: source changed by codeghar 
dpkg-buildpackage: host architecture amd64
 dpkg-source --before-build credner-1.0
 fakeroot debian/rules clean
dh clean
   dh_testdir
   dh_auto_clean
   dh_clean
 dpkg-source -b credner-1.0
dpkg-source: info: using source format `3.0 (quilt)'
dpkg-source: info: building credner using existing ./credner_1.0.orig.tar.gz
dpkg-source: warning: ignoring deletion of file credner.py
dpkg-source: info: building credner in credner_1.0-1.debian.tar.gz
dpkg-source: info: building credner in credner_1.0-1.dsc
 debian/rules build
dh build
   dh_testdir
   dh_auto_configure
   dh_auto_build
   dh_auto_test
 fakeroot debian/rules binary
dh binary
   dh_testroot
   dh_prep
   dh_installdirs
   dh_auto_install
   dh_install
   dh_installdocs
   dh_installchangelogs
   dh_installexamples
   dh_installman
   dh_installcatalogs
   dh_installcron
   dh_installdebconf
   dh_installemacsen
   dh_installifupdown
   dh_installinfo
   dh_installinit
   dh_installmenu
   dh_installmime
   dh_installmodules
   dh_installlogcheck
   dh_installlogrotate
   dh_installpam
   dh_installppp
   dh_installudev
   dh_installwm
   dh_installxfonts
   dh_installgsettings
   dh_bugfiles
   dh_ucf
   dh_lintian
   dh_gconf
   dh_icons
   dh_perl
   dh_usrlocal
   dh_link
   dh_compress
   dh_fixperms
   dh_strip
   dh_makeshlibs
   dh_shlibdeps
   dh_installdeb
   dh_gencontrol
dpkg-gencontrol: warning: Depends field of package credner: unknown substitution variable ${shlibs:Depends}
   dh_md5sums
   dh_builddeb
dpkg-deb: building package `credner' in `../credner_1.0-1_amd64.deb'.
 dpkg-genchanges  >../credner_1.0-1_amd64.changes
dpkg-genchanges: including full source code in upload
 dpkg-source --after-build credner-1.0
dpkg-buildpackage: full upload (original source is included)

cg@codeghar:~/custom-package/credner-1.0$ ls

debian

cg@codeghar:~/custom-package/credner-1.0$ cd ..

cg@codeghar:~/custom-package$ ls

credner-1.0                  credner_1.0-1.debian.tar.gz  credner-1.0.tar.gz
credner_1.0-1_amd64.changes  credner_1.0-1.dsc
credner_1.0-1_amd64.deb      credner_1.0.orig.tar.gz

cg@codeghar:~/custom-package$ sudo dpkg --install credner_1.0-1_amd64.deb

[sudo] password for codeghar:
Selecting previously unselected package credner.
(Reading database ... 84043 files and directories currently installed.)
Unpacking credner (from credner_1.0-1_amd64.deb) ...
Setting up credner (1.0-1) ...

cg@codeghar:~/custom-package$ dpkg --list credner

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name              Version           Description
+++-=================-=================-==================================================
ii  credner           1.0-1             First test deb package

cg@codeghar:~/custom-package$ dpkg --listfiles credner

/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/credner
/usr/share/doc/credner/copyright
/usr/share/doc/credner/changelog.Debian.gz
/usr/share/doc/credner/README.Debian

cg@codeghar:~/custom-package$ sudo dpkg --purge credner

(Reading database ... 84047 files and directories currently installed.)
Removing credner ...

cg@codeghar:~/custom-package$ dpkg --list credner

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name              Version           Description
+++-=================-=================-==================================================
un  credner                       (no description available)

From this tutorial you can learn the very basics of how to create a deb package. In our example package credner.py was not installed, and that’s alright. Our main purpose was to show the building blocks for now. We also installed a whole bunch of packages we might not have needed for this example. That’s ok, too, because as we continue our learning process we might need them.

My next goal is to create a deb package from a proper Python script. Stay tuned.

About these ads

Comments are closed.

Follow

Get every new post delivered to your Inbox.

Join 34 other followers

%d bloggers like this: