To install a .deb package with dpkg, you can use dpkg -i debFileName
. You can obtain a list of the installed packages on a system with
dpkg -l
or dpkg -l [optional pattern]
to filter the
list of packages shown by an optional pattern.
I've never created a .deb package and was curious as to how to do so. I thought I'd start with something simple by creating a .deb package for ibmonitor, since the program is just one Perl script. To build the package, I followed the instructions in the How to Build section of Debian Packages.
The first step in the process is to create the needed directories, which are as follows:
ProgramName-Version/ ProgramName-Version/DEBIAN ProgramName-Version/DEBIAN/control ProgramName-Version/usr/ ProgramName-Version/usr/bin/ ProgramName-Version/usr/bin/your_script
Since I wanted to create a package for ibmonitor, I created the following directories beneath my Documents directory:
$ mkdir ibmonitor_1.4-1 $ mkdir ibmonitor_1.4-1/DEBIAN $ mkdir -p ibmonitor_1.4-1/usr/bin
The -p
option for the mkdir
command will create
any intermediate directories needed, so mkdir -p ibmonitor_1.4-1/usr/bin
will create the usr
and usr/bin
subdirectories.
I named the top-level directory ibmonitor_1.4-1
, since the
standard Debian notation is to use all lowercase letters for a directory
name2 with the following
structure used for the name:
<project>_<major version>.<minor version>-<package
revision>
The next step is to create the control
file in the
DEBIAN
directory. The file is a text file with the following format
used for the information within it:
Package: ProgramName Version: VERSION Architecture: all Maintainer: YOUR NAME <EMAIL> Depends: python2.7, etc , etc, Installed-Size: in_kb Homepage: http://foo.com Description: Here you can put a one line description. This is the short Description. Here you put the long description, indented by 1 space.
For the ibmonitor control file, I put the following information in the text file:
Package: ibmonitor Version: 1.4-1 Architecture: all Maintainer: Jim Cameron <support@moonpoint.com> Depends: Perl Installed-Size: 31 Homepage: http://ibmonitor.sourceforge.net/ Description: Interactive bandwidth monitor Description: Interactive bandwidth monitor The program ibmonitor is an interactive linux console application which shows bandwidth consumed and total data transferred on all interfaces.
I used "all" for "Archtecture", since 5.6.8 Architecture of the Debian Policy Manual states all "indicates an architecture-independent package." I used "31" for the Installed-Size value, since the ibmonitor Perl script is 31,971 bytes in size and 5.6.20 Installed-Size states "The disk space is given as the integer value of the estimated installed size in bytes, divided by 1024 and rounded up." I used http://ibmonitor.sourceforge.net/ for the homepage, because that is the homepage used by the developer, Rohan Almeida and 5.6.23 Homepage states:
The URL of the web site for this package, preferably (when applicable) the site from which the original source can be obtained and any additional upstream documentation or information may be found. The content of this field is a simple URL without any surrounding characters such as <>.
I put the executable Perl script ibmonitor
in the user/bin
directory, since the instructions state:
The scripts placed at /usr/bin/ are directly called from the terminal, note that I didn't add an extension to the script. Also you can notice that the structure of the Debian package will be the structure of the program once it's installed. So if you follow this logic if your program has a single file, you can directly place it under ProgramName-Version/usr/bin/your_script, But if you have multiple files, you should place them under ProgramName-Version/usr/share/ProgramName/all your files and place only one file under /usr/bin/ that will call your scripts from /usr/share/ProgramName/
You can find information on other fields in Chapter 5 - Control files and their fields of the Debian Policy Manual.
In this case, the program consists of a single file, the
ibmonitor
Perl script, so I placed it directly under /usr/bin
.
I then changed ownership of all the directories and files to root.
$ sudo chown root:root -R ibmonitor_1.4-1 [sudo] password for jdoe: $
The ibmonitor Perl script was already executable, so I didn't need to change the Linux file permissions on it to make it executable.
$ ls -l ibmonitor_1.4-1/usr/bin total 32 -rwxrwxr-x 1 root root 31971 May 14 19:23 ibmonitor $
I then attempted to build the package with dpkg-deb --build
as per the instructions at
How to make a "Basic"
.deb, but received an error message:
$ dpkg-deb --build ibmonitor_1.4-1 dpkg-deb: error: parsing file 'ibmonitor_1.4-1/DEBIAN/control' near line 9 package 'ibmonitor': field name `bandwidth' must be followed by colon
The error occurred because, initially, I had the following for "Description":
Description: Interactive bandwidth monitor The program ibmonitor is an interactive linux console application which shows bandwidth consumed and total data transferred on all interfaces.
I then realized I needed a space before the second line of the longer description, so I changed the line to be the following, instead, after noting the instructions at How to make a "Basic".deb mentioned "the space before each line in the description is important":
Description: Interactive bandwidth monitor The program ibmonitor is an interactive linux console application which shows bandwidth consumed and total data transferred on all interfaces.
I was then able to successfully create the .deb file, which can be downloaded from ibmonitor .deb.
$ dpkg-deb --build ibmonitor_1.4-1 dpkg-deb: building package `ibmonitor' in `ibmonitor_1.4-1.deb'. $ ls -l *.deb -rw-r--r-- 1 jdoe jdoe 7614 May 14 21:09 ibmonitor_1.4-1.deb
You can check the contents of the .deb file with sudo dpkg -c
packagename
.
$ sudo dpkg -c ibmonitor_1.4-1.deb drwxrwxr-x root/root 0 2016-05-14 18:56 ./ drwxrwxr-x root/root 0 2016-05-14 18:56 ./usr/ drwxrwxr-x root/root 0 2016-05-14 19:23 ./usr/bin/ -rwxrwxr-x root/root 31971 2016-05-14 19:23 ./usr/bin/ibmonitor $
You can also use sudo dpkg -I packagename
to get
information on a package. Note: the option to obtain information
uses an upper case "I" rather than a lower case, which is used to install
a package.
$ sudo dpkg -I ibmonitor_1.4-1.deb new debian package, version 2.0. size 7584 bytes: control archive= 389 bytes. 366 bytes, 11 lines control Package: ibmonitor Version: 1.4-1 Architecture: all Maintainer: Jim Cameron <support@moonpoint.com> Depends: Perl Installed-Size: 31 Homepage: http://ibmonitor.sourceforge.net/ Description: Interactive bandwidth monitor The program ibmonitor is an interactive linux console application which shows bandwidth consumed and total data transferred on all interfaces.
You can install a .deb package with sudo dpkg -i packagename.deb
, where packagename is the name of the package. I installed
the software and verified it was placed in /usr/bin
on the system.
$ which ibmonitor $ sudo dpkg -i ibmonitor_1-4-1.deb Selecting previously unselected package ibmonitor. (Reading database ... 413086 files and directories currently installed.) Unpacking ibmonitor (from ibmonitor_1.4-1.deb) ... Setting up ibmonitor (1.4-1) ... jim@Didymus:~/Documents/blog$ which ibmonitor /usr/bin/ibmonitor $
I was then able to run the program by just typing
ibmonitor
. I checked the package information with
apt-cache show ibmonitor
and saw the following:
$ apt-cache show ibmonitor Package: ibmonitor Status: install ok installed Installed-Size: 31 Maintainer: Jim Cameron <support@moonpoint.com> Architecture: all Version: 1.4-1 Depends: perl Description: Interactive bandwidth monitor The program ibmonitor is an interactive linux console application which shows bandwidth consumed and total data transferred on all interfaces. Homepage: http://ibmonitor.sourceforge.net/ $
If you ever decide to remove a package after you've installed it, you
can use the command sudo dpkg -r packagename
where
packagename is the name of the installed package. E.g.:
$ sudo dpkg -r ibmonitor (Reading database ... 413086 files and directories currently installed.) Removing ibmonitor ... $
References: