This page looks best with JavaScript enabled

Using a server as a binary package server in Gentoo

 ·  🎃 kr0m

There are times when reusing the ebuild compilation from one Gentoo to another can be very beneficial, one of these cases is when you have more than one RaspBerryPi, following this strategy you would only compile the binaries on one of the RaspBerryPis and the other would download and install the precompiled packages. If we also add distcc to the RaspBerryPi that will act as a repo server, we will have the definitive combo, the compilation will be fast thanks to distcc and the installation of packages on the rest of the RaspBerryPis will be lightning fast.

The reuse of binary packages offers us several advantages:

  • Speed in the installation of ebuilds
  • Recovery of corrupted systems where the compiler does not work
  • Updating very old systems

To be able to install packages from one computer to another, they must share architecture and the CHOST parameter in /etc/make.conf, the C(XX)FLAGS parameters must be compatible on both computers, and the Uses must also be compatible on both.


We can configure a computer to generate the binary and save it (packages server) when it compiles an ebuild.

vi /etc/make.conf

FEATURES=buildpkg

Another option is to tell emerge to do it, but only for that package:

emerge -b PACKAGE

It is also possible to ONLY generate the binary but NOT install it:

emerge -B PACKAGE

NOTE: If you do not have the necessary dependencies to compile the package, the compilation will fail.

Another option is to generate a binary using the quickpkg command:

  • quickpkg "sys-devel/gcc" --include-config=y: Creates the binary package for all installed versions of gcc
  • quickpkg "/" --include-config=y: Creates the binary package for all installed packages
  • quickpkg "kde-base/*" --include-config=y: Creates the binary packages for all installed packages under the indicated category

The binary packages will be stored in /usr/portage/packages/:

vi /etc/make.conf

PKGDIR="/usr/portage/packages"

The binary packages can be served in different ways, ftp, http, ssh, but since the Rasp is not particularly powerful, we will do it through http with lighttpd as a webserver:

emerge www-servers/lighttpd

vi /etc/lighttpd/lighttpd.conf
server.document-root = "/usr/portage/packages"
/etc/init.d/lighttpd start
rc-update add lighttpd default

We configure the client (in the PKGDIR directory is where it will store the binaries downloaded from the master):

vi /etc/make.conf

PKGDIR="/usr/portage/packages"
PORTAGE_BINHOST="http://yourbinhostserver/"
FEATURES=getbinpkg

NOTE: It is also possible to make emerge install only one package from the binary server with emerge -g sys-devel/gcc and commenting out the FEATURES=getbinpkg option.

You can make emerge install software only from certain sources.

It only installs from:

  • --usepkg (-k): Uses binary packages located in PKGDIR, if they are not available, it compiles them.
  • --usepkgonly (-K): Uses binary packages located in PKGDIR, if they are not available, it gives an error.
  • --getbinpkg (-g): Downloads binary packages if they are not available, it compiles them if they are not.
  • --getbinpkgonly (-G): Downloads binary packages if they are not available, it gives an error if they are not.

There are times when we want to use the indicated preference but with the exception of some package:

emerge -uDNg @world --usepkg-exclude "sys-kernel/gentoo-sources virtual/*"

NOTE: The client must run emerge --rebuilt-binaries in case any binary has been updated on the master using revdep-rebuild or python-updater.

Every time an ebuild is compiled, a binary is generated. This implies that if updates are made, binaries from old versions will accumulate. To clean up and only leave the binaries of the ebuilds that are currently installed:

emerge app-portage/gentoolkit
eclean packages

The index of binary packages is located in /usr/portage/packages and is called Packages. When an ebuild is compiled, it is updated, but there are times when it may be necessary to force regeneration:

emaint binhost --fix

As a test, vim was installed in one way and another, obtaining the following results:

Compiling:

real    39m35.152s  
user    30m41.440s  
sys    1m33.210s  

Binaries:

real    3m1.905s  
user    2m21.840s  
sys    0m6.720s

As you can see, the performance increase is overwhelming.

If you liked the article, you can treat me to a RedBull here