34

I've read about how source-based linux distros like Gentoo can have considerable performance increases when compared to pre-built distros like Ubuntu because they install from source with optimizations for your particular system. Is is possible to build Ubuntu from source to get the same kind of benefit?

6
  • 3
    Install Gentoo, not Ubuntu, for that. Seriously, why use a distro that absolutely fails at source-based dependency management instead of one that rocks at it?
    – mathepic
    Mar 11, 2011 at 0:13
  • 7
    I'd be curious to see benchmarks between source and binary where they actually used the same stack versions and configuration. The comparison is usually an Ubuntu release (with its defaults) vs the latest possible Gentoo with an oddball filesystem and bizarre app defaults. The Ubuntu defaults are mostly pretty sane and that's where most of its performance comes from and that's why most straight comparisons put Ubuntu ahead of Gentoo.
    – Oli
    Mar 11, 2011 at 0:32
  • 1
    One great example of a bad comparison is this Linux Magazine article (free registration required to read) where they use different kernels, different Nvidia drivers, different X versions and different desktop environments. You might as well compare two different versions of Ubuntu. They'll show similar scales of difference.
    – Oli
    Mar 11, 2011 at 1:02
  • 1
    @Oli I doubt its really possible for Ubuntu to outstrip Gentoo in performance, even without stats, just by the optimized nature of a source distro. That said, the difference itself is unpredictable.
    – mathepic
    Mar 11, 2011 at 1:04
  • 4
    Performance increases of what? Network throughput, disk speed, process switching, pure math calculations, 3D-Graphics, bootup-time? Mar 11, 2011 at 2:18

3 Answers 3

47

Is is possible to build Ubuntu from source to get the same kind of benefit?

I am not sure about the benefits if you have fairly new hardware components but for the "Ubuntu from source" part of the question the answer is YES, you can build not only your favorite applications from source, but the entire operating system.

Here is how:

You need to install apt-build. Its a comandline tool like apt-get, but instead of downloading and installing the binary package, apt-build downloads the source code of the package, compiles it and then installs it to your system.

After you install it with

sudo apt-get install apt-build

you will be asked for an optimization level (medium is ok), whether you want to create an apt-build repo for APT (Yes) and a question about processor architecture (my intel i7 is considered core2 ). Of course all options can be reconfigured in this way:

dpkg-reconfigure apt-build

The above command offers two additional options for the gcc compiler and make builder. Their descriptions can be found in system manuals: man gcc and man make.

For a manual and available command options check

man apt-build

But the most useful are:

  • apt-build update — updates repo list, (like apt-get update)
  • apt-build upgrade — updates operating system, (like apt-get upgrade)
  • apt-build install program — installs an application,(like apt-get install)
  • apt-build world — something for hard-core users, it recompiles whole system!

For example:

Lets say you want to compile/install Gedit. Instead of apt-get install you just do

sudo apt-build install gedit

Apt-build makes use of deb-src entries contained in the /etc/apt/sources.list file so the compilation and installation processes are fully automatic (similar to emerge found in Gentoo). Apt-build downloads sources of the main application and its dependencies, compiles them, creates a deb package, and finally installs the package.

Some notes about apt-build world.

In my opinion don't attempt it, unless you have 24 or more hours available !

If so first thing you should, remove/disable/uninstall any third party applications (it better to do in a fresh install of Ubuntu) and then do :

sudo su
dpkg --get-selections | awk '{if ($2 == "install") print $1}'> /etc/apt/apt-build.list
exit

The above command will copy your full list of system packages to apt-build.list so that they can be compiled from source. Open that file

sudo gedit /etc/apt/apt-build.list

and remove any GCC/G++ entry

Then you can do :

sudo apt-build world

I suggest to add two options — --yes and --force-yes — to make the rebuilding process fully automatic.

5
  • 13
    +1 for the concrete answer, compared to "why build?" answers. I'd prefer to read also a more extensive opinion (even if subjective) about the benefits you could (or could not) obtain using apt-build.
    – enzotib
    May 26, 2011 at 12:33
  • 1
    There are currently +17 for this answer. But has anyone succesfully done it?
    – keiki
    Mar 16, 2014 at 16:35
  • 1
    @otakun85 I have used apt-build for compiling some packages successfully on Ubuntu (can't remember which release, one of 12.04|12.10|13.04), I did attempt apt-build world which was a mess. The man page for apt-build has this at the end BUGS Many., so expect trouble.
    – Phizes
    Sep 10, 2014 at 13:58
  • I find that instead of using apt-build world it's better to download a "Linux from Scratch" book, and do apt-build for every package listed in it. It specifies the correct order etc. For example I'm not sure, if apt-build world knows it should first recompile binutils, then gcc, then binutils again, gcc again, then programming languages, gzip etc. It seems it just compiles everything alphabetically. Nov 20, 2017 at 15:01
  • 1
    @SerhyiVynohradov: It wouldn't matter. LFS does that to avoid leaving any dependencies on libraries in the host system, but here it's just replacing everything in-place with compiled versions; they'll still be in the same location, have the same ABI, etc. Sep 24, 2019 at 15:35
3

You could start a flamewar and a huge debate about this kind of topic, but lets look at real life.

The speed of your OS greatly depends on what hardware you run it and that is the major factor.

I change distros frequently while most of the time staying with Arch, but is Arch way faster than Ubuntu? No.

Gnome with compiz on Ubuntu 10.10 useses about 300ram, on Arch 200ram, I have 4gb of ram, I don't feel the difference, but if you compare Ubuntu with gnome to Arch with awesome, there will be a huge boost in responsiveness and resource usage (300ram vs 50ram), but this only matters if you are choosing a distro for a netbook.

So if you have a fast desktop and don't want to spend time tinkering with your system just use Ubuntu, but if you have a netbook than consider using a lightweight WM on Arch :)

1
  • Well, at some point you may get to the situation where you have the latest hardware, but you still need to perform hour-long operations. And instead of setting up a bunch of servers to distribute the load, you don't mind to spend some time tinkering, to get that extra 20% boost. I never used Arch, but I tried Gentoo. And I saw that a lot of times there is no such thing as "faster distro". Instead there's a "distro with less software". You may have bare-bones system that is fast, but not secure. And when you install the other packages it becomes same speed as Ubuntu + apt-build. Nov 20, 2017 at 15:42
2

Apt-build is useful for more than performance, you can build custom distribution images and repository for specific hardware ready for mass install for your business. By this, I mean an optimized binary distribution if you know all the hardware will be the same. This way, only one computer does all the work compiling, and the rest are just upgraded using the remastered ISO. It's not completely just for lightweight or encoding. And a custom Installer ISO allows you to reinstall without recompiling if for some reason your system is unrecoverable after a disaster.

You must log in to answer this question.

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