# phpman > man > DEBUILD(1)

> **TLDR:** Build a Debian package from source.
>
- Build the package in the current directory:
  `debuild`
- Build a binary package only:
  `debuild -b`
- Do not run lintian after building the package:
  `debuild --no-lintian`

*Source: tldr-pages*

---

[DEBUILD(1)](https://www.chedong.com/phpMan.php/man/DEBUILD/1/markdown)                             General Commands Manual                            [DEBUILD(1)](https://www.chedong.com/phpMan.php/man/DEBUILD/1/markdown)



## NAME
       debuild - build a Debian package

## SYNOPSIS
       **debuild** [_debuild_ _options_] [_dpkg-buildpackage_ _options_] [**--lintian-opts** _lintian_ _options_]
       **debuild** [_debuild_ _options_] -- **binary**|**binary-arch**|**binary-indep**|**clean** ...

## DESCRIPTION
       **debuild**  creates all the files necessary for uploading a Debian package.  It first runs **dpkg-**
       **buildpackage**, then runs **lintian** on the _.changes_ file created (assuming that  **lintian**  is  in‐
       stalled),  and  finally  signs  the appropriate files (using [**debsign**(1)](https://www.chedong.com/phpMan.php/man/debsign/1/markdown) to do this instead of
       [**dpkg-buildpackage**(1)](https://www.chedong.com/phpMan.php/man/dpkg-buildpackage/1/markdown) itself; all relevant key-signing options are passed on).   Signing  will
       be  skipped if the distribution is _UNRELEASED_, unless **dpkg-buildpackage**'s **--force-sign** option
       is used.  Parameters can be passed to **dpkg-buildpackage** and **lintian**, where the parameters  to
       the  latter are indicated with the **--lintian-opts** option.  The allowable options in this case
       are **--lintian** and **--no-lintian** to force or skip the **lintian** step, respectively.  The  default
       is to run **lintian**.  There are also various options available for setting and preserving envi‐
       ronment variables, as described below in the Environment Variables section.  In  this  method
       of running **debuild**, we also save a build log to the file _../<package>_<version>_<arch>.build_.

       An  alternative  way of using **debuild** is to use one or more of the parameters **binary**, **binary-**
       **arch**, **binary-indep** and **clean**, in which case **debuild** will attempt to gain root privileges  and
       then  run  _debian/rules_  with the given parameters.  A **--rootcmd=**_gain-root-command_ or **-r**_gain-_
       _root-command_ option may be used to specify a method of gaining root  privileges.   The  _gain-_
       _root-command_  is  likely to be one of _fakeroot_, _sudo_ or _super_.  See below for further discus‐
       sion of this point.  Again, the environment preservation options may be used.  In this  case,
       **debuild**  will also attempt to run **dpkg-checkbuilddeps** first; this can be explicitly requested
       or switched off using the options **-D** and **-d** respectively.  Note also that if either of  these
       or  a **-r** option is specified in the configuration file option **DEBUILD**___**DPKG**___**BUILDPACKAGE**___**OPTS**,
       then it will be recognised even in this method of invocation of **debuild**.

       **debuild** also reads the **devscripts** configuration files as described below.   This  allows  de‐
       fault options to be given.

### Directory name checking
       In common with several other scripts in the **devscripts** package, **debuild** will climb the direc‐
       tory tree until it finds a _debian/changelog_ file before attempting to build the package.   As
       a  safeguard  against stray files causing potential problems, it will examine the name of the
       parent directory once it finds the _debian/changelog_ file, and check that the  directory  name
       corresponds  to the package name.  Precisely how it does this is controlled by two configura‐
       tion file variables **DEVSCRIPTS**___**CHECK**___**DIRNAME**___**LEVEL**  and  **DEVSCRIPTS**___**CHECK**___**DIRNAME**___**REGEX**,  and
       their corresponding command-line options **--check-dirname-level** and **--check-dirname-regex**.

       **DEVSCRIPTS**___**CHECK**___**DIRNAME**___**LEVEL** can take the following values:

       **0**      Never check the directory name.

       **1**      Only check the directory name if we have had to change directory in our search for _de__‐
              _bian/changelog_.  This is the default behaviour.

       **2**      Always check the directory name.

       The directory name is checked by testing whether the current directory name (as determined by
       [**pwd**(1)](https://www.chedong.com/phpMan.php/man/pwd/1/markdown))    matches    the    regex    given    by   the   configuration   file   option   **DE**‐‐
       **VSCRIPTS**___**CHECK**___**DIRNAME**___**REGEX** or by the command line option **--check-dirname-regex** _regex_.  Here
       _regex_  is  a  Perl regex (see [**perlre**(3perl)](https://www.chedong.com/phpMan.php/man/perlre/3perl/markdown)), which will be anchored at the beginning and the
       end.  If _regex_ contains a '/', then it must match the full directory path.  If not,  then  it
       must match the full directory name.  If _regex_ contains the string ´PACKAGE', this will be re‐
       placed by the source package name, as determined from the _changelog_.  The default  value  for
       the regex is: ´PACKAGE(-.+)?', thus matching directory names such as PACKAGE and PACKAGE-ver‐
       sion.

## ENVIRONMENT VARIABLES
       As environment variables can affect the building of a package, often unintentionally, **debuild**
       sanitises  the  environment by removing all environment variables except for **TERM**, **HOME**, **LOG**‐‐
       **NAME**, **GNUPGHOME**, **PGPPATH**,  **GPG**___**AGENT**___**INFO**,  **GPG**___**TTY**,  **DBUS**___**SESSION**___**BUS**___**ADDRESS**,  **FAKEROOTKEY**,
       **DEBEMAIL**,  **DEB**__*_,  the  (**C**, **CPP**, **CXX**, **LD** and **F**)**FLAGS** variables and their ___**APPEND** counterparts
       and the locale variables **LANG** and **LC**__*_.  **TERM** is set to `dumb' if it is unset,  and  **PATH**  is
       set to "/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11".

       If  a particular environment variable is required to be passed through untouched to the build
       process, this may be specified by using a **--preserve-envvar** _envvar_ (which can also be written
       as  **-e** _envvar_ option).  The environment may be left untouched by using the **--preserve-env** op‐
       tion.  However, even in this case, the **PATH** will be set to the sane  value  described  above.
       The  **only** way to prevent **PATH** from being reset is to specify a **--preserve-envvar** **PATH** option.
       But you are warned that using programs from non-standard locations can easily result  in  the
       package being broken, as it will not be able to be built on standard systems.

       Note  that  one  may  add  directories  to  the  beginning  of  the sanitised **PATH**, using the
       **--prepend-path** option. This is useful when one wishes to use tools such as **ccache**  or  **distcc**
       for building.

       It  is also possible to avoid having to type something like _FOO_**=**_bar_ **debuild** **-e** _FOO_ by writing
       **debuild** **-e** _FOO_**=**_bar_ or the long form **debuild** **--set-envvar** _FOO_**=**_bar_.

## SUPERUSER REQUIREMENTS
       **debuild** needs to be run as superuser to function properly.   There  are  three  fundamentally
       different  ways  to  do  this.  The first, and preferable, method is to use some root-gaining
       command.  The best one to use is probably [**fakeroot**(1)](https://www.chedong.com/phpMan.php/man/fakeroot/1/markdown), since it does not involve granting any
       genuine  privileges.   [**super**(1)](https://www.chedong.com/phpMan.php/man/super/1/markdown)  and [**sudo**(1)](https://www.chedong.com/phpMan.php/man/sudo/1/markdown) are also possibilities.  If no **-r** (or **--rootcmd**)
       option is given (and recall that **dpkg-buildpackage** also accepts a **-r** option) and  neither  of
       the following methods is used, then **-rfakeroot** will silently be assumed.

       The  second method is to use some command such as [**su**(1)](https://www.chedong.com/phpMan.php/man/su/1/markdown) to become root, and then to do every‐
       thing as root.  Note, though, that **lintian** will abort if it is run as root  or  setuid  root;
       this can be overcome using the **--allow-root** option of **lintian** if you know what you are doing.

       The  third  possible method is to have **debuild** installed as setuid root.  This is not the de‐
       fault method, and will have to be installed as such by the  system  administrator.   It  must
       also  be  realised  that anyone who can run **debuild** as root or setuid root has **full** **access** **to**
       **the** **whole** **machine**.  This method is therefore not recommended, but will work.   **debuild**  could
       be installed with mode 4754, so that only members of the owning group could run it.  A disad‐
       vantage of this method would be that other users would then not be able to use  the  program.
       There are many other variants of this option involving multiple copies of **debuild**, or the use
       of programs such as **sudo** or **super** to grant root privileges  to  users  selectively.   If  the
       sysadmin  wishes  to do this, she should use the **dpkg-statoverride** program to change the per‐
       missions of _/usr/bin/debuild_.  This will ensure that these permissions are  preserved  across
       upgrades.

## HOOKS
       **debuild** supports a number of hooks when running **dpkg-buildpackage**.  Note that the hooks **dpkg-**
       **buildpackage** to **lintian** (inclusive) are passed through to **dpkg-buildpackage** using its  corre‐
       sponding **--hook-**_name_ option.  The available hooks are as follows:

### dpkg-buildpackage-hook
              Run before **dpkg-buildpackage** begins by calling **dpkg-checkbuilddeps**.

              Hook is run inside the unpacked source.

              Corresponds to **dpkg**'s **init** hook.

### clean-hook
              Run  before  **dpkg-buildpackage** runs **debian/rules** **clean** to clean the source tree.  (Run
              even if the tree is not being cleaned because **-nc** is used.)

              Hook is run inside the unpacked source.

              Corresponds to **dpkg**'s **preclean** hook.

### dpkg-source-hook
              Run after cleaning the tree and before running **dpkg-source**.  (Run even if  **dpkg-source**
              is not being called because **-b**, **-B**, or **-A** is used.)

              Hook is run inside the unpacked source.

              Corresponds to **dpkg**'s **source** hook.

### dpkg-build-hook
              Run  after  **dpkg-source** and before calling **debian/rules** **build**.  (Run even if this is a
              source-only build, so **debian/rules** **build** is not being called.)

              Hook is run inside the unpacked source.

              Corresponds to **dpkg**'s **build** hook.

### dpkg-binary-hook
              Run between **debian/rules** **build** and **debian/rules** **binary**(**-arch**).  Run **only** if  a  binary
              package is being built.

              Hook is run inside the unpacked source.

              Corresponds to **dpkg**'s **binary** hook.

### dpkg-genchanges-hook
              Run after the binary package is built and before calling **dpkg-genchanges**.

              Hook is run inside the unpacked source.

              Corresponds to **dpkg**'s **changes** hook.

### final-clean-hook
              Run  after  **dpkg-genchanges**  and before the final **debian/rules** **clean**.  (Run even if we
              are not cleaning the tree post-build, which is the default.)

              Hook is run inside the unpacked source.

              Corresponds to **dpkg**'s **postclean** hook.

### lintian-hook
              Run (once) before calling **lintian**.  (Run even if we are not calling **lintian**.)

              Hook is run from parent directory of unpacked source.

              Corresponds to **dpkg**'s **check** hook.

### signing-hook
              Run after calling **lintian** before any signing takes place.  (Run even  if  we  are  not
              signing anything.)

              Hook is run from parent directory of unpacked source.

              Corresponds to **dpkg**'s **sign** hook, but is run by **debuild**.

### post-dpkg-buildpackage-hook
              Run after everything has finished.

              Hook is run from parent directory of unpacked source.

              Corresponds to **dpkg**'s **done** hook, but is run by **debuild**.

       A  hook  command  can  be  specified  either  in  the configuration file as, for example, DE‐
       BUILD_SIGNING_HOOK='foo' (note the hyphens change into underscores!) or as a command line op‐
       tion  **--signing-hook-foo**.  The command will have certain percent substitutions made on it: **%%**
       will be replaced by a single **%** sign, **%p** will be replaced by the package name, **%v** by the pack‐
       age version number, **%s** by the source version number, **%u** by the upstream version number.  Nei‐
       ther **%s** nor **%u** will contain an epoch.  **%a** will be **1** if the immediately following action is to
       be  performed  and  **0** if not (for example, in the **dpkg-source** hook, **%a** will become **1** if **dpkg-**
       **source** is to be run and **0** if not).  Then it will be handed to the shell to deal with,  so  it
       can  include  redirections and stuff.  For example, to only run the **dpkg-source** hook if **dpkg-**
       **source** is to be run, the hook could be something like: "if [ %a -eq 1 ]; then ...; fi".

       **Please** **take** **care** **with** **hooks**, as misuse of them can lead to  packages  which  FTBFS  (fail  to
       build from source).  They can be useful for taking snapshots of things or the like.

## OPTIONS
       For details, see above.

       **--no-conf**, **--noconf**
              Do  not read any configuration files.  This can only be used as the first option given
              on the command-line.

       **--rootcmd=**_gain-root-command_, **-r**_gain-root-command_
              Command to gain root (or fake root) privileges.

### --preserve-env
              Do not clean the environment, except for PATH.

       **--preserve-envvar=**_var_, **-e**_var_
              Do not clean the _var_ variable from the environment.

              If _var_ ends in an asterisk ("*") then all variables with names that match the  portion
              of _var_ before the asterisk will be preserved.

       **--set-envvar=**_var_**=**_value_, **-e**_var_**=**_value_
              Set the environment variable _var_ to _value_ and do not remove it from the environment.

       **--prepend-path=**_value_
              Once the normalized PATH has been set, prepend _value_ to it.

### --lintian
              Run  **lintian** after **dpkg-buildpackage**.  This is the default behaviour, and it overrides
              any configuration file directive to the contrary.

### --no-lintian
              Do not run **lintian** after **dpkg-buildpackage**.

### --no-tgz-check
              Even if we're running **dpkg-buildpackage** and the version number has a Debian  revision,
              do  not check that the _.orig.tar.gz_ file or _.orig_ directory exists before starting the
              build.

### --tgz-check
              If we're running **dpkg-buildpackage** and the version number has a Debian revision, check
              that  the _.orig.tar.gz_ file or _.orig_ directory exists before starting the build.  This
              is the default behaviour.

       **--username** _username_
              When signing, use **debrsign** instead of **debsign**.  _username_ specifies the credentials  to
              be used.

       **--**_foo_**-hook**=_hook_
              Set a hook as described above.  If _hook_ is blank, this unsets the hook.

### --clear-hooks
              Clears all hooks.  They may be reinstated by later command line options.

       **--check-dirname-level** _N_
              See the above section **Directory** **name** **checking** for an explanation of this option.

       **--check-dirname-regex** _regex_
              See the above section **Directory** **name** **checking** for an explanation of this option.

### -d

### -D

## CONFIGURATION VARIABLES
       The  two configuration files _/etc/devscripts.conf_ and _~/.devscripts_ are sourced by a shell in
       that order to set configuration variables.  Command line options can be used to override some
       of  these  configuration file settings, otherwise the **--no-conf** option can be used to prevent
       reading these files.  Environment variable settings  are  ignored  when  these  configuration
       files are read.  The currently recognised variables are:

       **DEBUILD**___**PRESERVE**___**ENV**
              If  this is set to _yes_, then it is the same as the **--preserve-env** command line parame‐
              ter being used.

       **DEBUILD**___**PRESERVE**___**ENVVARS**
              Which environment variables to preserve.  This should be  a  comma-separated  list  of
              variables.   This  corresponds  to using possibly multiple **--preserve-envvar** or **-e** op‐
              tions.

       **DEBUILD**___**SET**___**ENVVAR**__var_**=**_value_
              This corresponds to **--set-envvar=**_var_**=**_value_.

       **DEBUILD**___**PREPEND**___**PATH**
              This corresponds to **--prepend-path**.

       **DEBUILD**___**ROOTCMD**
              Setting this variable to _prog_ is the equivalent of **-r**_prog_.

       **DEBUILD**___**TGZ**___**CHECK**
              Setting this variable to _no_ is the same as the **--no-tgz-check** command line option.

       **DEBUILD**___**SIGNING**___**USERNAME**
              Setting this variable is the same as using the **--username** command line option.

       **DEBUILD**___**DPKG**___**BUILDPACKAGE**___**OPTS**
              These are options which should be passed to the invocation of **dpkg-buildpackage**.  They
              are  given before any command-line options.  Due to issues of shell quoting, if a word
              containing spaces is required as a single option, extra quotes will be required.   For
              example,  to  ensure that your own GPG key is always used, even for sponsored uploads,
              the configuration file might contain the line:

              DEBUILD_DPKG_BUILDPACKAGE_OPTS="-k'Julian Gilbey <<jdg@debian.org>>' -sa"

              which gives precisely two options.  Without the extra single quotes, **dpkg-buildpackage**
              would reasonably complain that _Gilbey_ is an unrecognised option (it doesn't start with
              a **-** sign).

              Also, if this option contains any **-r**, **-d** or **-D** options, these will always be taken ac‐
              count of by **debuild**.  Note that a **-r** option in this variable will override the setting
              in **DEBUILD**___**ROOTCMD**.

       **DEBUILD**__FOO__**HOOK**
              The hook variable for the _foo_ hook.  See the section on hooks above for more  details.
              By default, this is empty.

       **DEBUILD**___**LINTIAN**
              Should we run **lintian**?  If this is set to _no_, then **lintian** will not be run.

       **DEBUILD**___**LINTIAN**___**OPTS**
              These are options which should be passed to the invocation of **lintian**.  They are given
              before any command-line options, and the usage of this variable is  as  described  for
              the **DEBUILD**___**DPKG**___**BUILDPACKAGE**___**OPTS** variable.

       **DEVSCRIPTS**___**CHECK**___**DIRNAME**___**LEVEL**, **DEVSCRIPTS**___**CHECK**___**DIRNAME**___**REGEX**
              See  the  above section **Directory** **name** **checking** for an explanation of these variables.
              Note that these are package-wide configuration variables, and  will  therefore  affect
              all  **devscripts** scripts which check their value, as described in their respective man‐
              pages and in [**devscripts.conf**(5)](https://www.chedong.com/phpMan.php/man/devscripts.conf/5/markdown).

## EXAMPLES
       To build your own package, simply run **debuild** from inside the source  tree.   **dpkg-buildpack**‐‐
       [**age**(1)](https://www.chedong.com/phpMan.php/man/age/1/markdown) options may be given on the command line.

       The  typical  command  line  options  to build only the binary package(s) without signing the
       .changes file (or the non-existent .dsc file):

              debuild -i -us -uc -b

       Change the **-b** to **-S** to build only a source package.

       An example using **lintian** to check the resulting packages and passing options to it:

              debuild --lintian-opts -i

       Note the order of options here: the **debuild** options come first,  then  the  **dpkg-buildpackage**
       ones,  then  finally  the  checker options.  (And **lintian** is called by default.)  If you find
       yourself using  the  same  **dpkg-buildpackage**  options  repeatedly,  consider  using  the  **DE**‐‐
       **BUILD**___**DPKG**___**BUILDPACKAGE**___**OPTS** configuration file option as described above.

       To  build  a package for a sponsored upload, given _foobar_1.0-1.dsc_ and the respective source
       files, run something like the following commands:

              dpkg-source -x foobar_1.0-1.dsc
              cd foobar-1.0
              debuild -k0x12345678

       where 0x12345678 is replaced by your GPG key ID or other key identifier such  as  your  email
       address.  Again, you could also use the **DEBUILD**___**DPKG**___**BUILDPACKAGE**___**OPTS** configuration file op‐
       tion as described above to avoid having to type the **-k** option each time you  do  a  sponsored
       upload.

## SEE ALSO
       [**chmod**(1)](https://www.chedong.com/phpMan.php/man/chmod/1/markdown),  [**debsign**(1)](https://www.chedong.com/phpMan.php/man/debsign/1/markdown), [**dpkg-buildpackage**(1)](https://www.chedong.com/phpMan.php/man/dpkg-buildpackage/1/markdown), [**dpkg-checkbuilddeps**(1)](https://www.chedong.com/phpMan.php/man/dpkg-checkbuilddeps/1/markdown), [**fakeroot**(1)](https://www.chedong.com/phpMan.php/man/fakeroot/1/markdown), [**lintian**(1)](https://www.chedong.com/phpMan.php/man/lintian/1/markdown),
       [**su**(1)](https://www.chedong.com/phpMan.php/man/su/1/markdown), [**sudo**(1)](https://www.chedong.com/phpMan.php/man/sudo/1/markdown), [**super**(1)](https://www.chedong.com/phpMan.php/man/super/1/markdown), [**devscripts.conf**(5)](https://www.chedong.com/phpMan.php/man/devscripts.conf/5/markdown), [**dpkg-statoverride**(8)](https://www.chedong.com/phpMan.php/man/dpkg-statoverride/8/markdown)

## AUTHOR
       The original **debuild** program was written by  Christoph  Lameter  <<clameter@debian.org>>.   The
       current version has been written by Julian Gilbey <<jdg@debian.org>>.



DEBIAN                                    Debian Utilities                                [DEBUILD(1)](https://www.chedong.com/phpMan.php/man/DEBUILD/1/markdown)
