How to Compile Packages with makepkg in Arch Linux

Direct usage of makepkg can clutter your system setup. It’s essential to have the base-devel package group installed. By default, makepkg keeps build-time dependencies installed, even if they’re not needed to run the package. This behavior can be changed, but doing so may unnecessarily modify your system logs at /var/log/pacman.log.

This document focuses solely on using makepkg as a method for compiling software packages.

Step-by-Step: Using makepkg for Compilation

Begin by ensuring that the base-devel package group is installed. If it’s missing, makepkg will presume it’s present, and fail when a missing tool is required. Note that makepkg is included with the pacman package, which is already installed on your system.

Install base-devel

Run makepkg from within the directory containing the PKGBUILD, typically the directory cloned from AUR using git. By default, makepkg fetches the source, compiles it, and creates the package file.

Common makepkg Options

  • -s, --syncdeps: Installs all required dependencies for both building and using the software. For AUR-specific dependencies, pre-install them or ensure they exist in a local repo.
  • -r, --rmdeps: Removes unneeded dependencies after a successful build, particularly:
    • Build-time only dependencies.
    • If used without --install, also removes runtime dependencies.
  • -i, --install: Installs or upgrades the package post-build.
  • -c, --clean: Deletes temporary build files—useful during build troubleshooting.

Install the Package Automatically and Clean Up

This command installs the built package, retains runtime dependencies, and removes build-time ones:

Keep Dependencies for Future Upgrades

If you prefer not to install the package right away and want to retain all dependencies for a possible future rebuild or upgrade:

After building, you can either set up a local repository (explained elsewhere) or install the package file directly using:

 
# pacman -U <PKGNAME>-<PKGVER>-<PKGREL>-<ARCH>.pkg.tar.xz

 

 

Speed Up Package Creation with makepkg

By default, makepkg compresses packages into a .tar.xz archive using just a single thread for the xz compression process.

Enable Multi-Threading on Multi-Core Systems

If your system has multiple CPU cores, you can enable xz to use several threads by modifying the /etc/makepkg.conf file. Look for the line:

To use all available virtual CPU cores, change it to:

 
COMPRESSXZ=(xz -c -z - --threads=0)

If you’d like to limit resource usage to specific cores and reduce system load, set a fixed number of threads like this:

 
COMPRESSXZ=(xz -c -z - --threads=21)

Note: Setting more threads than your CPU has virtual cores will actually reduce performance.

Disable Compression to Build Faster

If storage space isn’t a concern and you want to speed up packaging, you can disable compression entirely. To do so, locate this line in /etc/makepkg.conf:

And change it to:

Bypass PGP Signature Checks (Not Recommended)

It’s best practice to verify and import all PGP signatures as outlined in the section titled “PGP Signature Error.”

Still, if you choose to run makepkg directly and want to skip PGP verification, you can use the --skippgpcheck option:

 

Conclusion: Efficiently Building Packages with makepkg

Compiling packages with makepkg gives you complete control over the build process on Arch Linux. By installing base-devel, configuring multi-threaded compression, and selectively handling dependencies, you can optimize both performance and system cleanliness.

While options like skipping PGP checks exist, it’s best to adhere to recommended security practices unless you’re fully aware of the implications. With the right adjustments, makepkg becomes a powerful and efficient tool for managing custom package.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in:

Moderne Hosting Services mit Cloud Server, Managed Server und skalierbarem Cloud Hosting für professionelle IT-Infrastrukturen

How to Install and Secure Apache OpenMeetings on CentOS 7

Apache, Tutorial

Linux file permissions with this comprehensive guide. Understand how to utilize chmod and chown commands to assign appropriate access rights, and gain insights into special permission bits like SUID, SGID, and the sticky bit to enhance your system’s security framework.