SlideShare a Scribd company logo
Introduction 1
What is Package System and Benefits 2
Known Package Management Systems on Linux Systems 2
Known Package Types On Linux Systems 3
Create Package for Debian Based Systems 3
What is Debian (.deb) Package? 3
What is Dependence? 4
Preconditions for Creating a Debian (.deb) Package 4
Install From Source Code 5
Create Debian (.deb) Package 6
Testing The Debian (.deb) Package 8
Updating an Existing Debian (.deb) Package. 8
Creating a Manual Debian (.deb) Package 9
Control File 11
Preinst File 12
Postinst File 12
Postrm & Prerm Files 13
Test Time 14
Displaying The Directory Structure 15
About The Author 16
Introduction
I will explain how to prepare a Debian package that all linux users can understand in this
article. Debian based Linux systems although there is a huge package repository,
sometimes it may be necessary to install a package which is not in the repository. In such a
case, as you can install the application from source code, you can also install the application
directly from the package manager by making it a .deb package.
Sometimes, a package in a package repository may not be enough for us to install values,
so we want to prepare the own package. For example, There is a squid3 package and it is
ready to install in the package repository but with this install, the sslbump feature may don't
come that we may need for squid. While installing from the source code also another way is
making it as a ( .deb ) package.
What is Package System and Benefits
Linux users and system managers need programs, drivers etc. They benefit from the
package repository to install dependencies with system tools.
The ready to install setups are expressed as a package for users install a package and
managing easily, ( updates, remove, version etc.)
For example, when you would like to install chrome application in your Linux system
( debian, ubuntu, etc. ). You just find the install link for chrome, download into the system
and without having to waste time setting up after the preconditions is completed. Using the
ready to install packages already in the package repository can save important time and
prevent any possible errors. Installing with "apt-get install chromium" takes seconds.
Known Package Management Systems on Linux Systems
apt =​ The goal of APT is to make life easier for users who use Debian based linux
distributions and to make system package management more understandable.
yum =​ This is using for package management in red-hat based distributions. The yum
features include: manage package, install package, remove a package, information of
package, update, etc.
aptıtude = ​This package manager was using especially in uninstalling dependencies also it
was good package manager at a long time ago. They all have the same function except for
some small usage changes.
pkg =​ This is the new package manager and it came with FreeBSD 10 operation system.
The pkg features include: install package, remove, update, lock/unlock the package.
Known Package Types On Linux Systems
Below is a list of mostly used package types in Linux based systems.
.rpm =​ This package type is developed by Red Hat also it has many powerful features and it
is adapted to many linux distributions.
.deb =​ This package type is also created for Debian based systems.
Create Package for Debian Based Systems
What is Debian (.deb) Package?
Debian packages are the packages that contain all the files necessary to apply the
commands or features.
Debian packages are divided to two;
Binary packages:​ This package contains the executive files, configuration files, man/info
pages and others documentations.
Source packages:​ Sources packages, the .dsc file that specifies of this package.
.orig.tar.gz file containing the original source code in the archive and .diff.gz file containing
the debian-specific changes in the file.
What is Dependence?
Dependency is the package needed for the package to work/compile.
There are two different dependence;
Build Dependency: ​Packages needed for package compilation.
Runtime Dependency:​ Packages needed for the package to work.
Preconditions for Creating a Debian (.deb) Package
We need to install some tools for create/prepare a debian package. Be sure you installed
properly the tools. First, we should update the system repository after that we may use the
following second command to install the tools what we need.
Note:​ Make sure that tools installed properly on the system. You can use this command for
check ( dpkg -s package_name ).
root#​ apt-get update ; apt-get upgrade -y
root# ​aptitude install build-essential binutils fakeroot lintian debhelper dh-make devscripts
patch libc6-dev file checkinstall makefile
Install From Source Code
The bzip2 tool is has used in this article as an example tool. In this example, I install bzip2
tool from the source code into the system and then we make it as a .deb package.
While I was preparing this article, I worked on this system. The commands, dependencies
may can be changed in differents linux systems.
Operating system features used;
Distributor ID: Debian
Description : Debian GNU/Linux 8.1 (jessie)
Version : 8.1
Kod adı : jessie
Let’s get it start.
First, we should create a directory in a random directory then enter into the directory and
after that install the bzip2 example tool. In this example, a directory called ​"test"​ is created
in the ​/home​ directory and entered in the directory after that installed the tool in this
directory.
root#​ cd /home/ ; mkdir test ; cd test
root#​ wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
First command going to open the bzip2.tar.gz file with tar command into the ​/home/test
directory and then we enter the directory that opens.
root#​ tar xvf bzip2-1.0.6.tar.gz -C /home/test/
root# ​cd /home/test/bzip2-1.0.6
Usually, many program's source codes comes with the ​INSTALL​ and ​README​ files. If you
don't know what is the program doing, how to install, how works, dependencies etc, it is so
helpful to read these files.
Note:​ When you using the following commands, you should be in ​bzip2-1.0.6/​ directory.
root#​ make
root# ​ make install
Create Debian (.deb) Package
We installed the bzip2 tool and we may use the following command convert this tool to the
.deb package. In the menu below we can edit the necessary areas by entering the number of
the information that we want to change.
Note:​ I didn't use dh_make command because it was too old, that's why I decided to use
debmake or checkinstall tools. These are so easy to use and so useful.
root#​ checkinstall -D make install
*****************************************
*** Debian package creation selected ***
*****************************************
This package will be built according to these values:
0 - Maintainer: [ ucribrahim@gmail.com ]
1 - Summary: [ This is my simple .deb package ]
2 - Name: [ bzip2 ]
3 - Version: [ 1.0.6 ]
4 - Release: [ 1 ]
5 - License: [ GPL ]
6 - Group: [ checkinstall ]
7 - Architecture: [ amd64 ]
8 - Source location: [ bzip2-1.0.6 ]
9 - Alternate source location: [ ]
10 - Requires: [ ]
11 - Provides: [ bzip2 ]
Enter a number to change any of them or press ENTER to continue:
Installing with make install...
========================= Installation results ===========================
if ( test ! -d /usr/local/bin ) ; then mkdir -p /usr/local/bin ; fi
if ( test ! -d /usr/local/lib ) ; then mkdir -p /usr/local/lib ; fi
if ( test ! -d /usr/local/man ) ; then mkdir -p /usr/local/man ; fi
chmod a+r /usr/local/man/man1/bzmore.1
chmod a+r /usr/local/man/man1/bzdiff.1
echo ".so man1/bzgrep.1" > /usr/local/man/man1/bzegrep.1
======================== Installation successful ==========================
Copying documentation directory...
./
./LICENSE
./README.XML.STUFF
./README.COMPILATION.PROBLEMS
./README
./CHANGES
Copying files to the temporary directory...OK
Compressing man pages...OK
Building file list...OK
Deleting temp dir...OK
********************************************************************
Done. The new package has been installed and saved to
/home/test/bzip2-1.0.6/bzip2_1.0.6-1_amd64.deb
You can remove it from your system anytime using:
dpkg -r bzip2
********************************************************************
You see the above results that mean the bzip2 tool is prepared. We can access the package
from this way (​ /home/test/bzip2-1.0.6/bzip2_1.0.6-1_amd64.deb​ ). If we want to remove it
that just we can use "dpkg -r bzip2" command.
Testing The Debian (.deb) Package
Package we have prepared, we can use scp, filezilla etc. tools send to another debian based
system for test and you can use the following commands to install package for test that we
have prepared. At the end of this, we will save time and we will not have to problems every
time to install from source code.
root# ​dpkg -i bzip2_1.0.6-1_amd64.deb
Updating an Existing Debian (.deb) Package.
If we want to take updates that we have prepared our own package, we can use the
following command.
root# ​apt-get install apt-file -y
Creating a Manual Debian (.deb) Package
In this part of the article, we will not use the source code of the tool. We will create our own
files and use bash to write the necessary commands into these files and prepare our own
.deb package.
Before start the topic, let’s look at the files what files are doing.
DEBIAN/control:​ This file what we will write program name, version, size, description,
dependencies of the file. Here is the contents of this file.
Package :​ Name of the application.
Version :​ Version of the application.
Source :​ The name of the application can be written.
Section :​ Which category the application entered.
Priority :​ The necessity of the application for the system.
Maintainer :​ The name or email address of the developer.
Architecture :​ Which architects are for.
Depends : ​Which packages it depend on. We separate to package names with commas (,).
Description :​ We can may write here a few sentences about what application doing.
DEBIAN/preinst : ​This file is the first start running while application is being installed.
Backup commands are usually written into this file when you update. You can write these
commands with bash or another language.
DEBIAN/postinst :​ This file is start after preinst file. Commands are written into this file for
the operations to be performed after installing the application.
DEBIAN/postrm or DEBIAN/prerm:​ Commands are written into this one of the both files for
delete the application.
DEBIAN/copyright :​ This file is contained the about package license information for the
debian system. You can review the license information section at
( ​https://www.debian.org/social_contract.en.html​ )
DEBIAN/rules :​ This is a ​Makefile​ for your debian package. Install a debian package with
dpkg command by to the information in this file.
DEBIAN/changelog :​ This file is a logbook describing the development of the program. If
you do something about program ( new features, resolved bugs, etc. ) you can write into this
file.
DEBIAN/readme & DEBIAN/install :​ Actually many linux users knows that what these files
are doing :). Usually the author is write information into this file about the how to install
program or what is this program doing etc.
Let’s get it start.
First, a directory named ​test​ is created in the ​/home ​directory.
root# ​mkdir /home/ibrahim/test
And then create a file called ​file.tar.gz​, which contains a ​test.txt​ file. After that use the
following command create a file called ​tmp​ in the ​test​ directory and when we create a file
called ​file.tar.gz​, it is sent into the ​tmp​ directory.
Note:​ When you send the file which called file.tar.gz, it shouldn’t be open. If you want to see
the contains of the file.tar.gz use this command ( tar tf file.tar.gz )
root# ​mkdir /home/ibrahim/test/tmp
root# ​cp /home/file.tar.gz /home/ibrahim/test/tmp/
Now we will use the following first command to create a file which is called ​DEBIAN​ into the
/​home/ibrahim/test/​ directory. (​The name must be DEBIAN​) After that we enter the
directory which is called ​DEBIAN​ and create the necessary files in this directory.
root# ​mkdir /home/ibrahim/test/DEBIAN
root# ​cd /home/ibrahim/test/DEBIAN
root# ​touch control postinst prerm
root# ​ls -l
Control File
This file what we will write program name, version, size, description, dependencies of the
file. Here is the contains of the file. After writing as below, you can press ​CTRL+O​ followed
by the ​enter​ key to save it, and then press ​CTRL+X​ to exit.
Note :​ In this area you can add or modify new areas by to your own.
root# ​nano control
Package: test
Version: 1.1.1
Architecture: all
Essential: no
Section: web
Priority: optional
Depends: php5 (>=2.3), php5-mysql
Maintainer: İbrahim UÇAR
Description: This is my example .deb package.
Preinst File
This file is start first running when a program installed. Backup commands are usually written
into this file when you update. This file isn’t in my example that’s why I won’t use this file in
article. If you want check the program updates, you should create this file and write
necessary commands into this file.
Postinst File
This file start running after preinst file. This file contains the operations to be performed after
the application is installed. Let me explain the topic for example after we installed the
package into the system, a directory will create which called is ​test​ into the ​/tmp​ directory.
Then the file named ​file.tar.gz​ will be opened in the ​/tmp/test​ directory which is created.
Copy all the sentences and paste it directly.
root# ​nano postinst
#!/bin/sh
FILE=file.tar.gz
DIRECTORY=test
mkdir -p "/tmp/$DIRECTORY"
tar xf "/tmp/$FILE" -C "/tmp/$DIRECTORY/"
Postrm & Prerm Files
These two files name are different but they are doing the same job. We will write commands
into this one of the two files for remove the package from the system. We are writing the
below commands into the which named is prerm file. This file will start, when a user has
used ( dpk -r test.deb , apt-get remove test​ ​) these commands to remove the package from
the system. The contents of the file are as follows.
Note:​ In my example, deleting the directory​ /tmp/test​ test is included. And bash command is
written into this file.
root# ​nano prerm
#!/bin/sh
if [ "$1" = "remove" ]; then
rm -rf /tmp/test
fi
Now It’s time to build .deb package. We will complete the mission and have own .deb
package when we use the following commands.
● In the first command, we created the .deb package with the existing directory name.
● In the second command, we created the .deb package with another name.
root# ​dpkg-deb --build /home/ibrahim/test/
dpkg-deb: building package `test in `test.deb'.
root# ​ls
test ​test.deb
root# ​dpkg-deb --build /home/ibrahim/test/ test.1.2.3.deb
dpkg-deb: building package `test in `test.1.2.3.deb'.
root# ​ls
test ​test.1.2.3.deb
Now we can use the following command for install the .deb package into the system.
root# ​dpkg -i test.deb
or
root# ​dpkg -i test.1.2.3.deb
If we want to remove the .deb package from the system, we can use the following
commands.
root# ​dpkg -r test.deb
or
root# ​dpkg -r test.1.2.3.deb
Test Time
In this stage, we will test own package is working or not by made manually. You can follow
the steps below.
After you had used below command, a directory will create which called is ​test​ into the ​/tmp
directory. Then the file named ​file.tar.gz​ will be opened in the ​/tmp/test​ directory which is
created.
As you can see output below, everything works correctly. The necessary file was opened
successfully where necessary directory. But If you can’t see the output as below as in your
system this means you missed something at somewhere.
root# ​dpkg -i test.1.2.3.deb
( Reading database ... 130889 files and directories currently installed.)
Preparing to unpack test.1.2.3.deb ...
Unpacking test (1.4.2) ...
Setting up test (1.4.2) …
root# ​ls -alh /tmp/test/ibrahimucar/
-rwxrwxr-x 1 ibrahim ibrahim 67 Nov 6 04:37 ​ test.txt
If we want to remove the package which is installed into the system. We can use the
following commands. Then you can look at the ​/tmp/test/ibrahimucar​ directory and you can
see that there is no such like this file.
root# ​dpkg -r test.1.2.3
( Reading database ... 130889 files and directories currently installed.)
Preparing to unpack test.1.2.3.deb ...
Unpacking test (1.4.2) ...
Setting up test (1.4.2) …
root# ​ls -alh /tmp/test/ibrahimucar/
ls: cannot access /tmp/test/ibrahimucar/: No such file or directory
Displaying The Directory Structure
After all the process are finished, we can use the following command if we want to see the
directory structure.
root# ​tree test
├── DEBIAN
│ ├── conffiles
│ ├── control
│ ├── postinst
│ └── prerm
└── tmp
└── file.tar.gz
2 directories, 5 files
About The Author
Author: İbrahim UÇAR
First Published Date: 16.01.2017
Contact Information;
➔ ucribrahim@gmail.com
➔ twitter.com/ucribrahim
➔ lifeoverlinux.com

More Related Content

PDF
How to Block Malicious Address by Using Feed Service?
PDF
Openfire xmpp server on windows server 2012 r2 with spark sso
PDF
Lpi 101 study_guide
PPT
Its3 Drupal
ODP
PDF
Lpi Part 1 Linux Fundamentals
PDF
55 best linux tips, tricks and command lines
PPT
Linux lecture6
How to Block Malicious Address by Using Feed Service?
Openfire xmpp server on windows server 2012 r2 with spark sso
Lpi 101 study_guide
Its3 Drupal
Lpi Part 1 Linux Fundamentals
55 best linux tips, tricks and command lines
Linux lecture6

What's hot (20)

PDF
Tutorial CentOS 5 untuk Webhosting
PPT
Anthony McKeown Drupal Presentation
PDF
linux-commandline-magic-Joomla-World-Conference-2014
PDF
Modul server debian 5
PDF
Refcard en-a4
PDF
Linux system admin useful commands
PDF
Linux Training For Beginners | Linux Administration Tutorial | Introduction T...
PPT
Linux commands
PPT
101 4.1 create partitions and filesystems
PPTX
UNIX/Linux training
DOCX
Linux final exam
PDF
Linux Security Quick Reference Guide
ODP
RPM: Speed up your deploy
PDF
InstallingRoRinLinux
PDF
Nelf2012
PDF
Part 6 of "Introduction to linux for bioinformatics": Productivity tips
PPT
Install and configure linux
PPT
Power point on linux commands,appache,php,mysql,html,css,web 2.0
PPT
Linux presentation
DOCX
Rhel 6.2 complete ebook
Tutorial CentOS 5 untuk Webhosting
Anthony McKeown Drupal Presentation
linux-commandline-magic-Joomla-World-Conference-2014
Modul server debian 5
Refcard en-a4
Linux system admin useful commands
Linux Training For Beginners | Linux Administration Tutorial | Introduction T...
Linux commands
101 4.1 create partitions and filesystems
UNIX/Linux training
Linux final exam
Linux Security Quick Reference Guide
RPM: Speed up your deploy
InstallingRoRinLinux
Nelf2012
Part 6 of "Introduction to linux for bioinformatics": Productivity tips
Install and configure linux
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Linux presentation
Rhel 6.2 complete ebook
Ad

Viewers also liked (20)

PDF
Red-Hat 7 Yeni Güvenlik Duvarı : firewalld
PDF
İş Ortamlarına Saldırı Tespit Sisteminin Kurulması
PDF
Linux Türevi İşletim Sistemlerinde Paket Hazırlama.
PDF
Linux Yaz Kampı 2016 pfSense Firewall ve Router Eğitim Dökümanı
DOCX
Marketing jobs in qatar
PPTX
Real estate investment
PDF
Virtual Learning with ON24
PPTX
All eyes on S4 - Gamification in customer engagement - Manu Melwin Joy
PPTX
Presentatie didacttool
DOCX
Informe transmision
PPTX
Viento
PPTX
Operations strategy
PDF
常用授權素材平台
PPTX
HISTORIA CLÍNICA NARRATIVA
PDF
Web Çatı Şablonlarının Güvenliği (SSTI) - Özgür Web Günleri 2016
PDF
Financial statement analysis of JK Tyre and CEAT Tyre
PPTX
Pfsense başlangıç
PPT
Pathways To Happiness for Areas with Low Happiness Scores in Satisfaction wit...
PDF
pfSense Firewall ve Router Eğitimi
Red-Hat 7 Yeni Güvenlik Duvarı : firewalld
İş Ortamlarına Saldırı Tespit Sisteminin Kurulması
Linux Türevi İşletim Sistemlerinde Paket Hazırlama.
Linux Yaz Kampı 2016 pfSense Firewall ve Router Eğitim Dökümanı
Marketing jobs in qatar
Real estate investment
Virtual Learning with ON24
All eyes on S4 - Gamification in customer engagement - Manu Melwin Joy
Presentatie didacttool
Informe transmision
Viento
Operations strategy
常用授權素材平台
HISTORIA CLÍNICA NARRATIVA
Web Çatı Şablonlarının Güvenliği (SSTI) - Özgür Web Günleri 2016
Financial statement analysis of JK Tyre and CEAT Tyre
Pfsense başlangıç
Pathways To Happiness for Areas with Low Happiness Scores in Satisfaction wit...
pfSense Firewall ve Router Eğitimi
Ad

Similar to How to Build Package in Linux Based Systems. (20)

ODP
The Gory Details of Debian packages
PDF
Debian Packaging tutorial
ODP
Packaging for the Maemo Platform
PDF
$ make install
PPTX
how to generate debian package from scratch
PDF
Debian packaging
PPTX
Software management in linux
PDF
Nuget is easier than you think and you should be using it as both a consumer ...
PPT
101 2.4 use debian package management
PDF
Debian Packaging
PDF
Advanced Usage of the Debian Packaging System
PPT
Linuxconcepts
PDF
Software Packaging for Cross OS Distribution
PDF
Course 102: Lecture 22: Package Management
ODP
How to build Debian packages
PDF
ovs-2.3.1 on debian 8.1
PDF
How to Install Python on Debian 12 Server
PDF
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)
PPTX
Linux Presentation
The Gory Details of Debian packages
Debian Packaging tutorial
Packaging for the Maemo Platform
$ make install
how to generate debian package from scratch
Debian packaging
Software management in linux
Nuget is easier than you think and you should be using it as both a consumer ...
101 2.4 use debian package management
Debian Packaging
Advanced Usage of the Debian Packaging System
Linuxconcepts
Software Packaging for Cross OS Distribution
Course 102: Lecture 22: Package Management
How to build Debian packages
ovs-2.3.1 on debian 8.1
How to Install Python on Debian 12 Server
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)
Linux Presentation

Recently uploaded (20)

PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
Testing WebRTC applications at scale.pdf
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
artificial intelligence overview of it and more
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPT
tcp ip networks nd ip layering assotred slides
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
DOCX
Unit-3 cyber security network security of internet system
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPTX
Introuction about WHO-FIC in ICD-10.pptx
Slides PDF The World Game (s) Eco Economic Epochs.pdf
international classification of diseases ICD-10 review PPT.pptx
Decoding a Decade: 10 Years of Applied CTI Discipline
Introuction about ICD -10 and ICD-11 PPT.pptx
Testing WebRTC applications at scale.pdf
RPKI Status Update, presented by Makito Lay at IDNOG 10
artificial intelligence overview of it and more
Slides PPTX World Game (s) Eco Economic Epochs.pptx
522797556-Unit-2-Temperature-measurement-1-1.pptx
tcp ip networks nd ip layering assotred slides
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
SASE Traffic Flow - ZTNA Connector-1.pdf
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Design_with_Watersergyerge45hrbgre4top (1).ppt
Cloud-Scale Log Monitoring _ Datadog.pdf
Unit-3 cyber security network security of internet system
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Introuction about WHO-FIC in ICD-10.pptx

How to Build Package in Linux Based Systems.

  • 1. Introduction 1 What is Package System and Benefits 2 Known Package Management Systems on Linux Systems 2 Known Package Types On Linux Systems 3 Create Package for Debian Based Systems 3 What is Debian (.deb) Package? 3 What is Dependence? 4 Preconditions for Creating a Debian (.deb) Package 4 Install From Source Code 5 Create Debian (.deb) Package 6 Testing The Debian (.deb) Package 8 Updating an Existing Debian (.deb) Package. 8 Creating a Manual Debian (.deb) Package 9 Control File 11 Preinst File 12 Postinst File 12 Postrm & Prerm Files 13 Test Time 14 Displaying The Directory Structure 15 About The Author 16
  • 2. Introduction I will explain how to prepare a Debian package that all linux users can understand in this article. Debian based Linux systems although there is a huge package repository, sometimes it may be necessary to install a package which is not in the repository. In such a case, as you can install the application from source code, you can also install the application directly from the package manager by making it a .deb package. Sometimes, a package in a package repository may not be enough for us to install values, so we want to prepare the own package. For example, There is a squid3 package and it is ready to install in the package repository but with this install, the sslbump feature may don't come that we may need for squid. While installing from the source code also another way is making it as a ( .deb ) package. What is Package System and Benefits Linux users and system managers need programs, drivers etc. They benefit from the package repository to install dependencies with system tools. The ready to install setups are expressed as a package for users install a package and managing easily, ( updates, remove, version etc.) For example, when you would like to install chrome application in your Linux system ( debian, ubuntu, etc. ). You just find the install link for chrome, download into the system and without having to waste time setting up after the preconditions is completed. Using the ready to install packages already in the package repository can save important time and prevent any possible errors. Installing with "apt-get install chromium" takes seconds.
  • 3. Known Package Management Systems on Linux Systems apt =​ The goal of APT is to make life easier for users who use Debian based linux distributions and to make system package management more understandable. yum =​ This is using for package management in red-hat based distributions. The yum features include: manage package, install package, remove a package, information of package, update, etc. aptıtude = ​This package manager was using especially in uninstalling dependencies also it was good package manager at a long time ago. They all have the same function except for some small usage changes. pkg =​ This is the new package manager and it came with FreeBSD 10 operation system. The pkg features include: install package, remove, update, lock/unlock the package. Known Package Types On Linux Systems Below is a list of mostly used package types in Linux based systems. .rpm =​ This package type is developed by Red Hat also it has many powerful features and it is adapted to many linux distributions. .deb =​ This package type is also created for Debian based systems.
  • 4. Create Package for Debian Based Systems What is Debian (.deb) Package? Debian packages are the packages that contain all the files necessary to apply the commands or features. Debian packages are divided to two; Binary packages:​ This package contains the executive files, configuration files, man/info pages and others documentations. Source packages:​ Sources packages, the .dsc file that specifies of this package. .orig.tar.gz file containing the original source code in the archive and .diff.gz file containing the debian-specific changes in the file. What is Dependence? Dependency is the package needed for the package to work/compile. There are two different dependence; Build Dependency: ​Packages needed for package compilation. Runtime Dependency:​ Packages needed for the package to work.
  • 5. Preconditions for Creating a Debian (.deb) Package We need to install some tools for create/prepare a debian package. Be sure you installed properly the tools. First, we should update the system repository after that we may use the following second command to install the tools what we need. Note:​ Make sure that tools installed properly on the system. You can use this command for check ( dpkg -s package_name ). root#​ apt-get update ; apt-get upgrade -y root# ​aptitude install build-essential binutils fakeroot lintian debhelper dh-make devscripts patch libc6-dev file checkinstall makefile Install From Source Code The bzip2 tool is has used in this article as an example tool. In this example, I install bzip2 tool from the source code into the system and then we make it as a .deb package. While I was preparing this article, I worked on this system. The commands, dependencies may can be changed in differents linux systems. Operating system features used; Distributor ID: Debian Description : Debian GNU/Linux 8.1 (jessie) Version : 8.1 Kod adı : jessie
  • 6. Let’s get it start. First, we should create a directory in a random directory then enter into the directory and after that install the bzip2 example tool. In this example, a directory called ​"test"​ is created in the ​/home​ directory and entered in the directory after that installed the tool in this directory. root#​ cd /home/ ; mkdir test ; cd test root#​ wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz First command going to open the bzip2.tar.gz file with tar command into the ​/home/test directory and then we enter the directory that opens. root#​ tar xvf bzip2-1.0.6.tar.gz -C /home/test/ root# ​cd /home/test/bzip2-1.0.6 Usually, many program's source codes comes with the ​INSTALL​ and ​README​ files. If you don't know what is the program doing, how to install, how works, dependencies etc, it is so helpful to read these files. Note:​ When you using the following commands, you should be in ​bzip2-1.0.6/​ directory. root#​ make root# ​ make install
  • 7. Create Debian (.deb) Package We installed the bzip2 tool and we may use the following command convert this tool to the .deb package. In the menu below we can edit the necessary areas by entering the number of the information that we want to change. Note:​ I didn't use dh_make command because it was too old, that's why I decided to use debmake or checkinstall tools. These are so easy to use and so useful. root#​ checkinstall -D make install ***************************************** *** Debian package creation selected *** ***************************************** This package will be built according to these values: 0 - Maintainer: [ ucribrahim@gmail.com ] 1 - Summary: [ This is my simple .deb package ] 2 - Name: [ bzip2 ] 3 - Version: [ 1.0.6 ] 4 - Release: [ 1 ] 5 - License: [ GPL ] 6 - Group: [ checkinstall ] 7 - Architecture: [ amd64 ] 8 - Source location: [ bzip2-1.0.6 ] 9 - Alternate source location: [ ] 10 - Requires: [ ] 11 - Provides: [ bzip2 ] Enter a number to change any of them or press ENTER to continue: Installing with make install... ========================= Installation results =========================== if ( test ! -d /usr/local/bin ) ; then mkdir -p /usr/local/bin ; fi if ( test ! -d /usr/local/lib ) ; then mkdir -p /usr/local/lib ; fi if ( test ! -d /usr/local/man ) ; then mkdir -p /usr/local/man ; fi chmod a+r /usr/local/man/man1/bzmore.1 chmod a+r /usr/local/man/man1/bzdiff.1 echo ".so man1/bzgrep.1" > /usr/local/man/man1/bzegrep.1 ======================== Installation successful ==========================
  • 8. Copying documentation directory... ./ ./LICENSE ./README.XML.STUFF ./README.COMPILATION.PROBLEMS ./README ./CHANGES Copying files to the temporary directory...OK Compressing man pages...OK Building file list...OK Deleting temp dir...OK ******************************************************************** Done. The new package has been installed and saved to /home/test/bzip2-1.0.6/bzip2_1.0.6-1_amd64.deb You can remove it from your system anytime using: dpkg -r bzip2 ******************************************************************** You see the above results that mean the bzip2 tool is prepared. We can access the package from this way (​ /home/test/bzip2-1.0.6/bzip2_1.0.6-1_amd64.deb​ ). If we want to remove it that just we can use "dpkg -r bzip2" command.
  • 9. Testing The Debian (.deb) Package Package we have prepared, we can use scp, filezilla etc. tools send to another debian based system for test and you can use the following commands to install package for test that we have prepared. At the end of this, we will save time and we will not have to problems every time to install from source code. root# ​dpkg -i bzip2_1.0.6-1_amd64.deb Updating an Existing Debian (.deb) Package. If we want to take updates that we have prepared our own package, we can use the following command. root# ​apt-get install apt-file -y
  • 10. Creating a Manual Debian (.deb) Package In this part of the article, we will not use the source code of the tool. We will create our own files and use bash to write the necessary commands into these files and prepare our own .deb package. Before start the topic, let’s look at the files what files are doing. DEBIAN/control:​ This file what we will write program name, version, size, description, dependencies of the file. Here is the contents of this file. Package :​ Name of the application. Version :​ Version of the application. Source :​ The name of the application can be written. Section :​ Which category the application entered. Priority :​ The necessity of the application for the system. Maintainer :​ The name or email address of the developer. Architecture :​ Which architects are for. Depends : ​Which packages it depend on. We separate to package names with commas (,). Description :​ We can may write here a few sentences about what application doing. DEBIAN/preinst : ​This file is the first start running while application is being installed. Backup commands are usually written into this file when you update. You can write these commands with bash or another language. DEBIAN/postinst :​ This file is start after preinst file. Commands are written into this file for the operations to be performed after installing the application. DEBIAN/postrm or DEBIAN/prerm:​ Commands are written into this one of the both files for delete the application. DEBIAN/copyright :​ This file is contained the about package license information for the debian system. You can review the license information section at ( ​https://www.debian.org/social_contract.en.html​ )
  • 11. DEBIAN/rules :​ This is a ​Makefile​ for your debian package. Install a debian package with dpkg command by to the information in this file. DEBIAN/changelog :​ This file is a logbook describing the development of the program. If you do something about program ( new features, resolved bugs, etc. ) you can write into this file. DEBIAN/readme & DEBIAN/install :​ Actually many linux users knows that what these files are doing :). Usually the author is write information into this file about the how to install program or what is this program doing etc. Let’s get it start. First, a directory named ​test​ is created in the ​/home ​directory. root# ​mkdir /home/ibrahim/test And then create a file called ​file.tar.gz​, which contains a ​test.txt​ file. After that use the following command create a file called ​tmp​ in the ​test​ directory and when we create a file called ​file.tar.gz​, it is sent into the ​tmp​ directory. Note:​ When you send the file which called file.tar.gz, it shouldn’t be open. If you want to see the contains of the file.tar.gz use this command ( tar tf file.tar.gz ) root# ​mkdir /home/ibrahim/test/tmp root# ​cp /home/file.tar.gz /home/ibrahim/test/tmp/ Now we will use the following first command to create a file which is called ​DEBIAN​ into the /​home/ibrahim/test/​ directory. (​The name must be DEBIAN​) After that we enter the directory which is called ​DEBIAN​ and create the necessary files in this directory. root# ​mkdir /home/ibrahim/test/DEBIAN root# ​cd /home/ibrahim/test/DEBIAN root# ​touch control postinst prerm root# ​ls -l
  • 12. Control File This file what we will write program name, version, size, description, dependencies of the file. Here is the contains of the file. After writing as below, you can press ​CTRL+O​ followed by the ​enter​ key to save it, and then press ​CTRL+X​ to exit. Note :​ In this area you can add or modify new areas by to your own. root# ​nano control Package: test Version: 1.1.1 Architecture: all Essential: no Section: web Priority: optional Depends: php5 (>=2.3), php5-mysql Maintainer: İbrahim UÇAR Description: This is my example .deb package. Preinst File This file is start first running when a program installed. Backup commands are usually written into this file when you update. This file isn’t in my example that’s why I won’t use this file in article. If you want check the program updates, you should create this file and write necessary commands into this file.
  • 13. Postinst File This file start running after preinst file. This file contains the operations to be performed after the application is installed. Let me explain the topic for example after we installed the package into the system, a directory will create which called is ​test​ into the ​/tmp​ directory. Then the file named ​file.tar.gz​ will be opened in the ​/tmp/test​ directory which is created. Copy all the sentences and paste it directly. root# ​nano postinst #!/bin/sh FILE=file.tar.gz DIRECTORY=test mkdir -p "/tmp/$DIRECTORY" tar xf "/tmp/$FILE" -C "/tmp/$DIRECTORY/" Postrm & Prerm Files These two files name are different but they are doing the same job. We will write commands into this one of the two files for remove the package from the system. We are writing the below commands into the which named is prerm file. This file will start, when a user has used ( dpk -r test.deb , apt-get remove test​ ​) these commands to remove the package from the system. The contents of the file are as follows. Note:​ In my example, deleting the directory​ /tmp/test​ test is included. And bash command is written into this file. root# ​nano prerm #!/bin/sh if [ "$1" = "remove" ]; then rm -rf /tmp/test fi
  • 14. Now It’s time to build .deb package. We will complete the mission and have own .deb package when we use the following commands. ● In the first command, we created the .deb package with the existing directory name. ● In the second command, we created the .deb package with another name. root# ​dpkg-deb --build /home/ibrahim/test/ dpkg-deb: building package `test in `test.deb'. root# ​ls test ​test.deb root# ​dpkg-deb --build /home/ibrahim/test/ test.1.2.3.deb dpkg-deb: building package `test in `test.1.2.3.deb'. root# ​ls test ​test.1.2.3.deb Now we can use the following command for install the .deb package into the system. root# ​dpkg -i test.deb or root# ​dpkg -i test.1.2.3.deb If we want to remove the .deb package from the system, we can use the following commands. root# ​dpkg -r test.deb or root# ​dpkg -r test.1.2.3.deb
  • 15. Test Time In this stage, we will test own package is working or not by made manually. You can follow the steps below. After you had used below command, a directory will create which called is ​test​ into the ​/tmp directory. Then the file named ​file.tar.gz​ will be opened in the ​/tmp/test​ directory which is created. As you can see output below, everything works correctly. The necessary file was opened successfully where necessary directory. But If you can’t see the output as below as in your system this means you missed something at somewhere. root# ​dpkg -i test.1.2.3.deb ( Reading database ... 130889 files and directories currently installed.) Preparing to unpack test.1.2.3.deb ... Unpacking test (1.4.2) ... Setting up test (1.4.2) … root# ​ls -alh /tmp/test/ibrahimucar/ -rwxrwxr-x 1 ibrahim ibrahim 67 Nov 6 04:37 ​ test.txt If we want to remove the package which is installed into the system. We can use the following commands. Then you can look at the ​/tmp/test/ibrahimucar​ directory and you can see that there is no such like this file. root# ​dpkg -r test.1.2.3 ( Reading database ... 130889 files and directories currently installed.) Preparing to unpack test.1.2.3.deb ... Unpacking test (1.4.2) ... Setting up test (1.4.2) … root# ​ls -alh /tmp/test/ibrahimucar/ ls: cannot access /tmp/test/ibrahimucar/: No such file or directory
  • 16. Displaying The Directory Structure After all the process are finished, we can use the following command if we want to see the directory structure. root# ​tree test ├── DEBIAN │ ├── conffiles │ ├── control │ ├── postinst │ └── prerm └── tmp └── file.tar.gz 2 directories, 5 files About The Author Author: İbrahim UÇAR First Published Date: 16.01.2017 Contact Information; ➔ ucribrahim@gmail.com ➔ twitter.com/ucribrahim ➔ lifeoverlinux.com