Skip to main content

Creating Arch Linux Packages

By February 7, 2017September 12th, 2022No Comments

Creating Arch Linux PackagesIn this blog, we take a look at creating Arch Linux packages. Working through an example we create an Arch Linux package with the latest SED source code.  In Arch, we have pkg files stat make up the software packages used to encapsulate out software that we install and remove from the system. These files are very similar to the deb files we have in Debian and the rpm files used in Red Hat.

Using Software Packages

In all Linux distributions, we want to use software packages where possible when installing software. The process of installing is simplified and the package contains the packaged programs and dependencies lists. More than this though, we are able to easily list what is installed and remove software that is no longer needed as we have a database of what is installed.

Latest Software Versions

When a package is not available in the repository then you can choose to download and compile the source code. This, though, is not the best where we have many servers and it is not so easy to audit or remove software installed in this way. This is where we can create our own packages so we can maintain the integrity of our installed software base across the server estate. We may also choose this method where the latest version of the vendor software has not made it into the Arch repositories. We will use SED 4.4 for the demonstration, the current version in the repo is 4.2.

Creating Arch Linux Packages for SED 4.4

We will be working with the source code for SED, the Stream Editor. The version we have in the repos as of February 2017 is version 4.2 and the latest version from the vendor itself is 4.4. Although, there may not be a lot of difference we may need these new features and hence the need to package sed 4.4.

Build Host

We need an Arch system up and running to build the packages on. This needs to be the same architecture of the target clients. Ensure that we have the base-devel package group installed as this will give as there required compilers and the makepkg command.

$ sudo pacman -S base-devel

With this installed and ready top go we can create a directory to work with. We should be logged in as a standard user and NOT root. Move to your home directory and create a folder called abs for Arch Build System. We won’t be using the ABS command but the directory name still makes sense. In that directory, we can create a directory named sed. Representing the package that we are creating.

$ cd
$ midir -p abs/sed
$ cd abs/sed

Create the PKGBUILD File

The command makepkg will read it work inventory from the PKGBUILD file. A sample file can be copied from /usr/share/pacman/PKGBUILD.proto. The file should be copied across to the sed directory and named PKGBUILD. The file should be edited so it appears similar to the following:

pkgdesc="SED the stream editor"
build() {
        cd "$pkgname-${pkgver}"
        ./configure --prefix=/usr

package() {
        cd "$pkgname-${pkgver}"
        make DESTDIR="$pkgdir" install


  • The source function is used to download the source code tarball
  • The build function creates the Makefile and compiles the code
  • The package function installs the target code to a local subdirectory so the install can run as a standard user and not actually install onto the system. This steps also creates the package from the dummy directory.

The structure of the abs directory should be similar to this:

└── sed
    └── PKGBUILD

Execute makepkg

To create the package we run the aptly named program makepkg. This is from the base-devel package group. We first run with the -g option which will create an MD5 Checksum for the downloaded source file and add it to the PKGBUILD file. We then run makepkg proper. This all should be run from the ~/abs/sed directory.

$ makepkg -g >> PKGBUILD && makepkg

This will run through the complete instruction set that we added to the PKGBUILD file and create a file named: sed-4.4-1-x86_64.pkg.tar.xz. This we can copy to the target systems or add to our own repo. In the demo we create the package file to another Arch Linux system for installation:

$ scp sed-4.4-1-x86_64.pkg.tar.xz

We can then install it from that system with:

$ sudo pacman -U sed-4.4-1-x86_64.pkg.tar.xz

I hope you enjoy the video demonstration: