How to build deb package for ubuntu 18.04

8,828

This forum thread outlines a basic way to create a .deb package for distribution, and indeed, this does not involve a need for root privileges. I replicate it here with credit to the forum user curvedinfinity, as a very nice illustration of the basics involved.

The checkinstall tool described in the link you provided is not primarily intended for general .deb package preparation. It is primarily intended to install software you compile yourself in a way that the package manager knows about it. Accordingly, it requires root privileges. The trick used indeed is to create a .deb file specific for your system, and then install that one. The .deb it creates may not be suited for general distribution.

Excerpt from Ubuntuforums by curedfinity:

Decide on the name of your package. Standard debian notation is all lowercase in the following format:

<project>_<major version>.<minor version>-<package revision>

For example, you could name your first package...

helloworld_1.0-1

Create a directory to make your package in. The name should be the same as the package name.

mkdir helloworld_1.0-1

Pretend that the packaging directory is actually the root of the file system. Put the files of your program where they would be installed to on a system.

mkdir helloworld_1.0-1/usr
mkdir helloworld_1.0-1/usr/local
mkdir helloworld_1.0-1/usr/local/bin
cp "~/Projects/Hello World/helloworld" helloworld_1.0-1/usr/local/bin

Now create a special metadata file with which the package manager will install your program...

mkdir helloworld_1.0-1/DEBIAN
gedit helloworld_1.0-1/DEBIAN/control

Put something like this in that file...

Package: helloworld
Version: 1.0-1
Section: base
Priority: optional
Architecture: i386
Depends: libsomethingorrather (>= 1.2.13), anotherDependency (>= 1.2.6)
Maintainer: Your Name <[email protected]>
Description: Hello World
 When you need some sunshine, just run this
 small program!

(the space before each line in the description is important)

Now, supposing your current directory is the one containing the folder helloworld_1.0-1, you just need to make the package:

dpkg-deb --build helloworld_1.0-1

And you're done!

End of citation.

Share:
8,828

Related videos on Youtube

Abdul
Author by

Abdul

Updated on September 18, 2022

Comments

  • Abdul
    Abdul over 1 year

    I am interested to build a deb package for ubuntu 18.04. I have found this article help me, How to create NGINX debian package from souce?.

    My question is, Is it safe to build deb package using root privilege? Because I have to use sudo checkinstall, instead of checkinstall.

    So far I know, we should not build rpm package using root privilege. And I am wondering if this term is not available for deb package.

    TIA

  • Abdul
    Abdul about 5 years
    So, it is a security when install the deb package that is created by sudo checkinstall on vps production server, isnt it?
  • vanadium
    vanadium about 5 years
    What I outlined would be standard procedure, which does not need root permissions. The deb produced by checkinstall may serve your purposes, but involves using root permissions. The general safety caution associated with running processes with elevated permissions apply if you go that way. Your question is primarily focused to create a deb without the need for root permissions, as suggested by the title and the first and last paragraphs.
  • Abdul
    Abdul about 5 years
    Is it safe doing this and then install it to on another machine ?
  • vanadium
    vanadium about 5 years
    Feel free to ask a new question. Comments are intended to improve the question and the answers, not for discussion.
  • Abdul
    Abdul about 5 years
    Pardon me the confusion. I am just a newbie with no where linux basic knowledge.
  • Abdul
    Abdul about 5 years
    The Part I am still confused : cp "~/Projects/Hello World/helloworld" helloworld_1.0-1/usr/local/bin Could you give me the simple explanation?
  • vanadium
    vanadium about 5 years
    That is a copy command that copies the compiled executable of the program to the /usr/bin folder under the folder containing the files for the .deb file.
  • Andor Kiss
    Andor Kiss over 3 years
    So, from where does one execute the <dpkg-deb --build helloworld_1.0-1> command? From inside the /DEBIAN folder? From the top folder? Can you please be a little more specific? TIA
  • Andor Kiss
    Andor Kiss over 3 years
    Okay, one has to move OUT of the directories that you just created and run the build command.