10

I use apt-get -b source and this command download and compile source with one core of cpu, Is there any way to compile package in debian with apt package manager with multiple cpu cores ? like -j option in make command : make -jX .

Thanks.

1 Answer 1

12

I use the command debuild from the devscripts package, which calls dpkg-buildpackage from the dpkg-dev package. This has some advantages over using dpkg-buildpackage directly, for example it creates a build log automatically. Normal usage after running

apt-get source pkgname

is

debuild -uc -us

But instead you can do (for example)

debuild -uc -us -j4

This passes the -j flag to dpkg-buildpackage.

Here is the relevant section from man dpkg-buildpackage.

-jjobs Number of jobs allowed to be run simultaneously, equivalent to the make(1) option of the same name. Will add itself to the MAKEFLAGS environment variable, which should cause all subsequent make invocations to inherit the option. Also adds parallel=jobs to the DEB_BUILD_OPTIONS environment variable which allows debian/rules files to use this information for their own purposes. The parallel=jobs in DEB_BUILD_OPTIONS environment variable will override the -j value if this option is given.

This is of course not guaranteed to work. The build will have to actually use either MAKEFLAGS or DEB_BUILD_OPTIONS in a suitable fashion for this to have an effect.

I have never used apt-get -b source, but you might be able to pass suitable flags via that command line too. However, I would recommend doing this build in two steps. In any case, building directly after a download does not work most of the time. Usually you have to at least install build dependencies first. In situations where you are doing backports or otherwise working with packaging that is not designed for the same release you are trying to build on, you may need to modify the packaging before attempting to build.

7
  • 1
    This is good (i will try it), but my question is about "is there any way to use apt-get with multiple cores" ?
    – alireza
    Jan 2, 2015 at 13:48
  • The commands I've listed are functionally equivalent to apt-get -b source. That command will also call dpkg-buildpackage. Jan 2, 2015 at 13:50
  • this way not work and this error happened for every program that i try to compile : codepad.org/hXe9HrMI
    – alireza
    Feb 5, 2015 at 7:29
  • @alirezaimi First, I notice you are running this command as root. That is a really bad idea. Don't do that. Second, I'm not sure why you are getting this error, but that has nothing to my answer to this question. Feb 5, 2015 at 7:48
  • 2
    Portable way for -j option: -j`nproc` to detect number of CPUs (or -j`getconf _NPROCESSORS_ONLN` if nproc insn't installed).
    – pevik
    Oct 4, 2015 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .