Compiling from source faster: multi-threading in `make`

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, December 29, 2014

Follow me on Twitter as @mattiasgeniar

I’m not quite sure how I ever missed this, but the make command has as parameter that controls how many simultaneous jobs it can run at once. The default “compile from source” flow looks like this.

$ make clean
$ ./configure
$ make
$ make install

Step 1, 2 and 4 can’t really be speed up (I think?), but the step that actually builds the binaries/libraries/… is make, and with the -j flag you can tell it how many jobs to run at the same time.

For instance, if you have 4 CPU cores, you can let make run 4 threads at once.

$ make clean
$ ./configure
$ make -j 4
$ make install

If you just specify -j, without a number, it’ll spawn an infinite number of jobs, but that may not be exactly what you want. It’ll be safer to limit this to the amount of cores you have available (and that aren’t currently maxed out).

I’ll try to remember this one, next to my other ground rules for compiling from source.

For instance, when building PHP from source, a normal make took 14 minutes, a make -j 2 (since I have 2 cores available) took 7.5 minutes. That’s a clear win in time right there!



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.