This repository contains the code of the simplest program in the C
programming language and step by step instructions on how to package this software into a deb
package.
Stage 1
- Go to home directory and clone repository from github:
cd ~ && git clone https://[email protected]/SergeyIvanovDevelop/DEB-Package-Creation && cd DEB-Package-Creation
Stage 2
- Initial data: there is a directory
~/DEB-Package-Creation/Example_deb_create
, and it contains empty directoryCreate_deb
. Go toExample_deb_create
:cd Example_deb_create
Stage 3
- Install everything you need to build the
C
program and build thedeb
packages:sudo apt-get install build-essential dh-make
Stage 4
- Create file
hello_world_deb.c
andMakefile
(if they are not) to it in directoryCreate_deb
hello_world_deb.c :
---------------------------
int main() {
printf(“Hello, World\n”);
return 0;
}
---------------------------
Makefile :
---------------------------
all:
gcc hello_world_deb.c -o hello_world_deb
clean:
rm hello_world_deb || true
---------------------------
and create empty directory Run_deb
: mkdir Run_deb
Stage 5
- We build the executable file (from the
Create_deb
directory):make -f Makefile
The hello_world_deb
file should appear in the Create_deb
directory
Stage 6
- From the
Create_deb
directory, execute the command to create theCreate_deb/debian
directory (a service directory for building adeb
package):dh_make -p mydebpackagename_0.0.1 --createorig
, where mydebpackagename_0.0.1
is the name and version of the deb
package, respectively
In the terminal for executing this command, 2 questions will be asked.
1st question: Type of package: (single, indep, library, python) [s/i/l/p]?".
Must select "s"
2nd question: "Maintainer Name : Sergey Email-Address : sergey@unknown Date : Thu, 16 Jul 2020 10:55:34 +0300 Package Name : mydebpackagename Version : 0.0.1 License : blank Package Type : single Are the details correct? [Y/n/q]".
Must select "Y"
If the command is successful, the runtime terminal will display "Done. Please edit the files in the debian/ subdirectory now."
Stage 7
- Change to the
Create_deb/debian
directory (from theCreate_dir
directory):cd debian
Stage 8
- Open the
changelog
file for editing:nano changelog
Stage 9
- Change the word
unstable
to the wordtrusty
. Save and exit the file(Ctrl+O, Ctrl+X)
Stage 10
- Open the
rules
file for editing:nano rules
Stage 11
- In the
%
target, before thedh $@
command, add the following line:mkdir ~/DEB-Package-Creation/Example_deb_create/Run_deb/mydebpackagename_dir || true
We will place the executable file of our program in this folder.
Note: "|| true" is necessary so that when trying to re-create the ~/DEB-Package-Creation/Example_deb_create/Run_deb/mydebpackagename_dir
directory, the deb
package creation script does not throw an error (and this script tries to execute this command several times (duplicating this command for some internal purposes - you can see on the Internet how to avoid this by overriding various default targets - but this problem is easier and more elegantly solved)
Stage 12
- Create a file
mydebpackagename.install
and open it for editing:
mydebpackagename.install:
------------------------------------
hello_world_deb.c /home/user/DEB-Package-Creation/Example_deb_create/Run_deb/mydebpackagename_dir
hello_world_deb /home/user/DEB-Package-Creation/Example_deb_create/Run_deb/mydebpackagename_dir
Makefile /home/user/DEB-Package-Creation/Example_deb_create/Run_deb/mydebpackagename_dir
------------------------------------
Stage 13
- Now you need to change to the
Create_deb
directory from theCreate_deb/debian
directory:cd ..
Stage 14
- From the
Create_deb
directory, you need to run the command to build thedeb
package:dpkg-buildpackage
Stage 15
- After that, you need to go down one directory from the
Create_deb
directory (to theExample_deb_create
directory):cd ..
Stage 16
- Run the
ls
command and make sure that the filemydebpackagename_0.0.1-1_amd64.deb
has actually been created:ls
Stage 17
- Run the command to install the
deb
package:sudo dpkg -i mydebpackagename_0.0.1-1_amd64.deb
Stage 18
- From the
Example_deb_create
directory change to theExample_deb_create/Run_deb/mydebpackagename_dir
directory:cd Run_deb/mydebpackagename_dir
Stage 19
- Make sure there are 3 files there (
hello_world_deb.c
,hello_world_deb
,Makefile
):ls
Stage 20
- Run the
hello_world_deb
executable and make sure it is running (the lineHello, World
should appear in the console):./hello_world_deb
Stage 21
- If the line is displayed - congratulations, you have correctly compiled and installed a simple
deb
package with your own software!
Creation deb-package is CC BY-NC-SA 3.0 licensed.