This brief tutorial describes how to speed up compilation process when installing packages from AUR using Ccache in Arch Linux and its variants EndeavourOS and Manjaro Linux.
The reasons why I (and everyone) prefer Arch Linux over other Linux distributions are:
- It is a rolling release, so you will always have the last version of your applications,
- Robust and powerful package manager Pacman,
- Arch User Repository (AUR),
- and Arch Wiki.
As you may already know, Pacman is the simple and powerful package manager for Arch Linux and its derivatives.
Arch Wiki doesn't need any introduction. It is an incredible documentation site, contributed by well-experienced users, where you can find tons of guides, tips and tricks etc.
And, finally the AUR or Arch User Repository. In this repository, almost every piece of software that runs on Linux is available. It is the largest repository maintained by trusted users from all over the world.
If you use AUR regularly, I've got a good news for you. You can speed up the compilation process when installing packages from AUR using ccache compiler.
What is Ccache?
For those wondering, ccache is a fast c/c++ compiler which is used to speed up the compilation process. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. It supports C, C++, Objective-C and Objective-C++.
Speed Up Compilation Process When Installing Packages From AUR
Step 1: You need to install ccache package first. Ccache is available in the default repositories.
To install Ccache in Arch Linux, EndeavourOS, Manjaro Linux, run:
$ sudo pacman -S ccache
Step 2: After installing ccache, edit
$ sudo vi /etc/makepkg.conf
Step 3: Find and uncomment ccache from the following line (remove the exclamation mark) to enable caching.
BUILDENV=(fakeroot !distcc color ccache check !sign)
Then uncomment and edit the
MAKEFLAGS value to reflect your CPU threads. Say for example, if your CPU has 8 threads (4 cores), then update the value as shown below:
Press ESC key, then type
:wq and press ENTER to save the file and close it.
Tip: To find the number of CPU cores in your system, refer the following link.
Step 4: Then, edit your
$ vi ~/.bashrc
Step 5: Add the following line to enable for command line compilations:
Save the file and close it.
Step 6: Finally, source the
bashrc file to take effect the changes using command:
$ source ~/.bashrc
Now, you will notice the difference while compiling packages from AUR. Please note that ccache may take a few seconds longer to compile a program the first time, but the subsequent compiles will be much faster.