Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am compiling some programs here and I have 4 cores. Is there a way to tell make, cmake or gcc to compile using all cores or something to that affect.

share|improve this question
up vote 13 down vote accepted

If a package supports it you can use the -j flag to allow parallel jobs running, e.g.:

make -j8

More details on this flag can be found in the Stackoverflow question Why does make -j perform better when it is passed a number larger than the number of cores available?.

Distributed compilation

If you have multiple machines, give distcc a go. On the involved machines, sudo apt-get install distcc. Assuming that your build machine is

  • on the helper machines, run:

    sudo distccd --log-file=/tmp/distccd.log --daemon -a
  • On the build machine, before running configure or cmake you have to specify hosts that you want to use for the build process. Optionally, specify the number of simultaneous jobs after a slash (defaulting to 4):

    export DISTCC_HOSTS='localhost/4'

    Make the compiler use distcc:

    export PATH="/usr/lib/distcc:$PATH"

    Now configure or cmake the application and build with:

    make -j$(distcc -j)

    Note that if you've put /usr/lib/distcc twice in your PATH, it'll fail. Be sure to set /usr/lib/distcc only once in your PATH.

For more details, see the manual pages for distcc(1) and distccd(1).

share|improve this answer
OMG that J is good. I went from 15 minutes to less than 1. thanks L. – Luis Alvarado Feb 23 '12 at 17:22
It can get faster with distcc, compilation of PHP was done in 2 minutes, the kernel was done in 3 minutes (three i5 machines) – Lekensteyn Feb 23 '12 at 17:24
Will try with distcc when i get to work. Was asking a similar question about this yesterday. Maybe you can help with it here:… – Luis Alvarado Feb 23 '12 at 17:39
Running distccd as root seems like a bad plan. I've not used it for a few reasons but when I did I can't have used root because I didn't have permission on those machines. – ams Feb 24 '12 at 9:23
@ams You do not need to run it as root. If you run it as root and want to switch users, use distccd --user nobody. Otherwise, it'll run under the user who executed it. – Lekensteyn Feb 24 '12 at 9:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.