Linux – How to create Archlinux package from scratch

arch linuxpackaging

I'm using archlinux and i want to make my own packages with my own modification ,

So , how can i create a new archlinux package with source code and how to modify existing one?

and finally, how to download the binary or source code for archlinux packages like :

apt download [package name]

or

apt source [package name]

in debian or ubuntu package manager?

Best Answer

Arch Linux packages are built with makepkg tool. In order to build a package from scratch you need to create a PKGBUILD file which defines package metadata and build steps. This file is essentially a Bash script.

A very basic PKGBUILD file could look like this:

pkgname=arch-update-notify
pkgver=0.2
pkgrel=1
pkgdesc="Notify all users with X sessions about available updates with a popup."
arch=("any")
url="https://github.com/zoresvit/arch-update-notify"
license=('MIT')
depends=('libnotify' 'python')
source=("git://github.com/zoresvit/${pkgname}/")
sha1sums=('SKIP')

package() {
    cd "$pkgname"
    mkdir -p $pkgdir/usr/bin
    install -D -m755 ./updates.py $pkgdir/usr/bin/$pkgname
}

It creates a package which installs updates.py file into /usr/bin directory.

For more information see ArchWiki page, which describes in depth how Arch Linux packaging works and how to properly build a package.

There is also an ArchLinux User Repository (AUR) which contains PKGBUILD files created by users. You can choose a package and click view PKGBUILD to get better idea how others write their PKGBUILD files.

You can use pacman to download a package:

pacman -Sw <package_name>

This will download a package with all its dependencies into /var/cache/pacman/pkg.

For more information on using pacman you can also check out corresponding ArchWiki page.

Related Question