When using Ccache to speed up compilation, all cached object files and metadata are stored in a local directory. By default, on most systems, this directory is located inside the home directory. This setup works in most cases, but it can cause problems if the home partition has limited space, you need faster access on a dedicated SSD, or you're in a shared build environment where cache files should be centralized. This tutorial provides 2 methods how to set cache directory using Ccache.
Before making any changes, we can check the current cache directory with:
ccache -k cache_dir
Example output:
/home/ubuntu/.cache/ccache
We can configure Ccache to use a different cache directory, either permanently through the configuration file or temporarily with an environment variable.
1. Configuration file
We can set the cache directory in the configuration file by using the following command:
ccache -o cache_dir=/tmp/ccache
To confirm the change, list the current configuration:
ccache -p
You'll see an entry like this:
(/home/ubuntu/.config/ccache/ccache.conf) cache_dir = /tmp/ccache
This means the option has been stored in the configuration file. If you want to remove this option, simply open ccache.conf
and delete the line containing cache_dir
.
2. Environment variable
Alternatively, we can temporarily override the cache directory with an environment variable:
export CCACHE_DIR=/tmp/ccache
To revert to the default location, just unset the variable:
unset CCACHE_DIR
Leave a Comment
Cancel reply