How to Compile Software from Source on Arch Linux
Categories:
5 minute read
Arch Linux is a rolling release, minimalist distribution that empowers users with full control over their systems. One of the most powerful aspects of Arch is its emphasis on customization—right down to the software you run. While the Arch User Repository (AUR) offers access to a massive collection of pre-built user-contributed packages, there are situations where compiling software from source is beneficial—or even necessary.
Whether you’re optimizing for your hardware, modifying functionality, or working with software that isn’t available in a package manager, compiling from source gives you maximum flexibility. In this guide, we’ll walk you through the complete process of compiling software from source on Arch Linux, from installing build tools to cleaning up after a successful build.
Why Compile Software from Source?
Before diving into the how, let’s look at the why:
- Access bleeding-edge versions before they hit repositories.
- Enable or disable specific features via
./configure
orcmake
options. - Optimize performance for your CPU architecture using compiler flags.
- Apply custom patches or tweak the code to suit your needs.
- Learn more about how software is built and packaged in Linux environments.
That said, compiling from source also has trade-offs: it can be time-consuming, dependency resolution is manual, and updates aren’t automatic unless you manage them with tools like the AUR or makepkg
.
Step 1: Prepare Your System
Before building any software, ensure your system has the essential development tools installed.
1.1 Install Base Development Packages
The Arch base system does not include compilation tools by default. Install the necessary base development tools with:
sudo pacman -S base-devel
This includes make
, gcc
, autoconf
, automake
, pkgconf
, libtool
, and other utilities commonly used to build software.
📝 Tip: All AUR helpers assume
base-devel
is installed. If you’re using the AUR, you likely already have it.
1.2 Optional: Version Control Systems
If the source code is hosted on Git, Mercurial, or Subversion, you may need the corresponding tools:
sudo pacman -S git mercurial subversion
Step 2: Download the Source Code
There are typically three ways to obtain the source code:
2.1 From a Tarball
Many projects release compressed source archives:
wget https://example.com/software-1.0.tar.gz
tar -xzf software-1.0.tar.gz
cd software-1.0
2.2 From a Git Repository
For the latest development version:
git clone https://github.com/username/project.git
cd project
If you need a specific branch or commit:
git checkout branch-name
2.3 From the AUR (Optional)
If the software exists in the AUR, but you want to modify it, download its PKGBUILD
:
git clone https://aur.archlinux.org/example-package.git
cd example-package
You can now inspect or modify the PKGBUILD
script before building.
Step 3: Read the Documentation
Before building, read the documentation provided:
README
INSTALL
docs/
directory
These usually outline:
- Dependencies
- Build tools required (e.g.,
cmake
,meson
) - Custom build options
Step 4: Install Dependencies
Most software requires libraries or other packages to compile. Use pacman -Ss
to search for them or refer to the documentation.
Example
If the software needs libpng
and freetype2
:
sudo pacman -S libpng freetype2
📝 Tip: Use
pkg-config --cflags --libs <library>
to check if required libraries are available.
Step 5: Configure the Build
Depending on the project, you may encounter one of several build systems:
5.1 Autotools (./configure
)
This is the classic Unix build system.
./configure --prefix=/usr
You can customize build options using --enable
, --disable
, --with
, or --without
.
5.2 CMake
If the project uses CMake:
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
5.3 Meson + Ninja
For newer software:
meson setup build --prefix=/usr
cd build
Step 6: Compile the Software
Once configured, compile the software.
Using Make
make -j$(nproc)
The -j
flag allows parallel compilation using all CPU cores.
Using Ninja (Meson projects)
ninja
⚠️ Compilation time varies depending on the software size and your hardware.
Step 7: Install the Software
After compiling, you can install the software system-wide.
Using Make
sudo make install
Using Ninja
sudo ninja install
By default, this installs to /usr/local
, unless you specified another prefix.
Step 8: Post-Installation Checks
8.1 Verify Binary Location
Ensure the binary is in your PATH
. For example:
which software-name
8.2 Run the Program
Try running the program and test its functionality.
software-name --version
Step 9: Keeping Track of Manually Installed Software
Software compiled from source isn’t tracked by pacman
, so updates and uninstalls are manual. You have a few options:
9.1 Use a Package Manager Wrapper (makepkg
)
Instead of installing manually, build a .pkg.tar.zst
package using makepkg
:
makepkg -si
This way, the package is installed and managed by pacman
, making upgrades or removals easy.
9.2 Use checkinstall
(Not available in Arch by default)
checkinstall
can create a package automatically during make install
, but it’s more common on Debian-based systems.
9.3 Maintain a Build Log
Keep a record (text file, spreadsheet, etc.) of:
- Software name
- Version
- Source URL
- Installation path
This helps when it’s time to update or uninstall.
Step 10: Uninstalling Compiled Software
If the software uses Autotools and was installed with make install
, you may be able to uninstall with:
sudo make uninstall
Only works if the developer included uninstall support in the Makefile.
Otherwise, you’ll need to manually delete files from /usr/local
or wherever you installed it.
Bonus: Troubleshooting Tips
Build Fails with Missing Headers
Check the error message and install the missing development libraries. For example, a missing png.h
implies:
sudo pacman -S libpng
Dependency Conflicts
Avoid mixing AUR and manual installations in the same prefix path (/usr
). Prefer /usr/local
or sandboxed environments for experimental builds.
Use clean
Targets
To rebuild from scratch:
make clean
Or delete the build/
directory (in CMake/Meson builds) and reconfigure.
Conclusion
Compiling software from source on Arch Linux opens the door to powerful customization and optimization, putting you in full control of what runs on your system. While it requires more effort than using pacman
or AUR helpers like yay
, it can be extremely rewarding, especially for advanced users and developers.
Remember to:
- Keep your system updated.
- Read the build documentation thoroughly.
- Track what you install manually.
- Use
makepkg
to build manageable.pkg.tar.zst
packages when possible.
Whether you’re patching upstream code, customizing your software stack, or contributing to open-source projects, understanding the process of source compilation is a valuable skill in any Linux user’s toolbox.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.