How to Fix “Fontconfig Error: No Writable Cache Directories”
“Fontconfig error: No writable cache directories” means the affected process cannot write to any cache directory in its active Fontconfig configuration; the usual fix is to create a writable user cache or correct its ownership. Run the checks as the account that launches the failing application, not automatically as root. Use the symptoms below to distinguish a permissions problem from a container restriction or a separate configuration error.
| Symptom | Likely Cause | Fix |
|---|---|---|
| The user cache directory does not exist | Missing cache directory or an uninitialized home directory | Create the directory and test writing to it |
| The cache exists but creating a file fails | Incorrect ownership, permissions, or access restrictions | Repair the affected private directory |
| The application works in a terminal but fails as a service | Different user, environment, or filesystem access | Configure a writable cache for the service account |
| The error occurs in Docker, Kubernetes, or serverless execution | Runtime user cannot write to the image filesystem | Provide a writable cache location owned by the runtime user |
The output also contains unknown element "its:rules" or configuration-loading errors |
Incompatible library and configuration files, or a configuration override | Fix the configuration problem before changing cache permissions |
What the Fontconfig Cache Error Means
Fontconfig helps applications discover and select fonts. Its caches store information about font directories so applications do not have to scan every font file repeatedly. These caches are normally managed automatically by the library, according to the Fontconfig Developers Reference.
The account running your application needs access to a suitable cache location when Fontconfig must write cache data. That account might be your desktop user, a service account, or a numeric user ID inside a container.
A system cache such as /var/cache/fontconfig is not normally writable by an ordinary user. That alone is not a fault: an application can use readable system caches and maintain its own writable user cache.
Keep font directories and cache directories separate in your diagnosis. An application may be able to read its fonts perfectly well while being unable to save their cache.
How to Fix the Fontconfig Cache Directory Error
The error is resolved by using a writable Fontconfig cache directory accessible to the application’s actual account and environment.
Step 1: Check the Application’s User and Environment
- Run the diagnostics in the environment where the failure happens. For a container, that means inside the container as its runtime user; for a service, inspect its configured account and environment.
idDo not assume your interactive shell has the same permissions as the failing process.
- Inspect the home directory and any Fontconfig configuration overrides.
printf 'HOME=%s\nFONTCONFIG_FILE=%s\nFONTCONFIG_PATH=%s\n' "$HOME" "$FONTCONFIG_FILE" "$FONTCONFIG_PATH"An incorrect
HOMEcan send the application toward another account’s directories.FONTCONFIG_FILEandFONTCONFIG_PATHcan make it load configuration different from the system default. - Check the cache-home override.
echo "$XDG_CACHE_HOME"The usual per-user cache is
~/.cache/fontconfig. WhenXDG_CACHE_HOMEis set, the usual location becomes$XDG_CACHE_HOME/fontconfig; the variable should contain an absolute path. If the override points somewhere unwritable, and your home directory is writable, temporarily reset it:export XDG_CACHE_HOME="$HOME/.cache"This changes the current shell and processes launched from it. It does not update an already-running application, service, or container.
The remaining user-directory commands assume the default cache location. If you intentionally use a different XDG_CACHE_HOME, substitute that location’s fontconfig subdirectory in each command.
Step 2: Create the Cache Directory and Test Writing
- Inspect the default user cache.
ls -ld ~/.cache/fontconfigIf the directory does not exist, create it:
mkdir -p ~/.cache/fontconfig - Test whether the application’s account can write there.
touch ~/.cache/fontconfig/test-temp-fileUse an unused test filename. If you created the file successfully, remove it afterward:
rm -- ~/.cache/fontconfig/test-temp-file - Interpret a failed test before changing anything: – Permission denied: inspect ownership, directory permissions, ACLs, and any sandbox restrictions. – Read-only file system: provide writable storage; changing ownership cannot make a read-only mount writable. – No space left on device: check available space and inodes. – Disk quota exceeded: address the account’s storage quota.
If writing succeeds, leave ownership alone. The application may be using a different configuration, account, or cache path.
Step 3: Repair Ownership Only Where It Is Wrong
- Inspect the cache and its parents.
ls -ld "$HOME" "$HOME/.cache" "$HOME/.cache/fontconfig"The application needs permission to traverse the parent directories as well as write to the cache. A root-owned cache is a common consequence of previously running an application with elevated privileges.
- If only the Fontconfig cache tree has the wrong owner, make a narrowly scoped repair. Run this from the intended user’s shell, not from a root login shell:
sudo chown -R "$(id -u):$(id -g)" "$HOME/.cache/fontconfig"If the parent cache directory itself also has incorrect ownership, repair that directory without recursively changing unrelated caches:
sudo chown "$(id -u):$(id -g)" "$HOME/.cache"A broader repair is appropriate only when you have confirmed that the entire private cache tree belongs to this user and has incorrect ownership. If both the intended account and its group are named
$USER, that repair is:sudo chown -R "$USER:$USER" ~/.cacheDo not apply this recursive command to a shared cache, another account’s home, or a mounted directory with intentionally different owners. Some accounts do not have a group matching their username.
- Set private permissions on the user’s Fontconfig cache directory.
chmod 700 ~/.cache/fontconfigMode
700allows the owner to read, write, and traverse the directory while denying access to other accounts. It is suitable for a private user cache, not a cache deliberately shared by multiple service users. - Repeat the write test. If writing still fails despite correct ownership, investigate filesystem restrictions and security-policy denial logs rather than granting world-write access or disabling security controls.
Avoid making /var/cache/fontconfig writable by everyone. A functioning per-user cache is normally the better solution.
Step 4: Inspect the Loaded Configuration and Debug Output
- Check which configuration files the command-line Fontconfig installation loads.
fc-conflistCommon locations include
/etc/fonts/fonts.conf, included files under/etc/fonts/conf.d/, and the user configuration at~/.config/fontconfig/fonts.conf. A configuredXDG_CONFIG_HOMEchanges the user configuration location. If the application bundles its own Fontconfig library, its configuration may differ from the command-line tools’ configuration. - Inspect custom
<cachedir>entries. A configuration containing only a protected system-cache path may leave an ordinary user with nowhere to write. For an XDG-based user cache, the relevant XML element is:<cachedir prefix="xdg">fontconfig</cachedir>This belongs inside the existing
<fontconfig>element of a configuration file the application actually loads. Preserve the rest of that file, including font-directory declarations and includes. Do not overwrite the entire system configuration with this fragment. Default configurations may already contain an appropriate user-cache entry. If yours does, investigate why the application is not using it rather than adding duplicates. - Launch the affected application with debugging enabled. For a basic Font Manager diagnostic:
FC_DEBUG=1 font-managerReplace
font-managerwith the affected application’s launch command when debugging another application. An important correction:FC_DEBUG=1enables font-matching diagnostics; it is not a reliable way to list attempted cache directories. For cache and configuration diagnostics, use:FC_DEBUG=1040 font-managerThis combines Fontconfig’s cache and configuration debug flags. Use the output to identify the configuration and cache locations used by the failing application itself.
Make any necessary configuration correction, save the file, and continue with a fresh application process. A running process may retain its previously loaded configuration.
Step 5: Rebuild the Cache and Relaunch the Application
- Rebuild as the application’s user, using the corrected environment.
fc-cache -f -vThe
-fflag forces rescanning even when caches appear valid;-vdisplays progress and cache information. Check the output for the intended writable cache location and any remaining errors. Do not addsudojust to make this command succeed. A successful root-run rebuild does not demonstrate that the application’s own account can write its cache. - Fully exit and restart the affected application from the corrected environment. Repeat the operation that originally produced the error, such as rendering an SVG, generating a PDF, or opening Font Manager.
- Make a successful environment correction persistent in the launcher that actually starts the application. That could be a shell startup file, service definition, container configuration, or CI job, not necessarily your interactive shell configuration.
Fixing Fontconfig in Containers, CI, and Services
Docker and Kubernetes
A cache created successfully during an image build may still fail at runtime. Build steps often run as root, while the application runs under a non-root account or a user ID supplied by the deployment.
For an existing image that already contains Fontconfig, fonts, and an appuser account and group, this Dockerfile fragment prepares a private cache:
USER root
RUN mkdir -p /home/appuser/.cache/fontconfig \
&& chown -R appuser:appuser /home/appuser/.cache
ENV HOME=/home/appuser
ENV XDG_CACHE_HOME=/home/appuser/.cache
USER appuser
RUN fc-cache -f -v
Replace the account and paths with those used by your application. Preserve the image’s required application startup instructions.
Rebuild the image, launch it with the real deployment settings, and repeat the failing rendering operation. A runtime user override or a mounted volume can change access even when the build succeeded.
For a read-only root filesystem, provide a writable volume for the cache. In Kubernetes, an emptyDir volume is a common option: mount it at the chosen cache-home path, set XDG_CACHE_HOME to that path, and ensure the container’s user or group can write there. Fontconfig’s usual XDG cache entry uses a fontconfig subdirectory beneath it.
Deploy the change and verify the actual workload, not only a build-time command. Mounting a volume over an image directory hides the directory contents and ownership prepared during the build.
Services and CI Jobs
A service does not necessarily inherit your terminal’s HOME or XDG_CACHE_HOME. Its home may be absent, inaccessible, or deliberately blocked by sandboxing.
For a persistent service:
- Provision a dedicated cache directory owned by the service account.
- Set
XDG_CACHE_HOMEin the service’s environment to the absolute parent directory of its Fontconfig cache. - Ensure the service’s filesystem restrictions permit writes there.
- Restart the service and repeat the operation that produced the error.
Point XDG_CACHE_HOME at the corresponding provisioned directory rather than assuming that provisioning alone changes Fontconfig’s environment.
For CI or serverless execution, use a job-owned or application-owned directory within writable storage. /tmp is usable only when that runtime makes it writable; do not assume every read-only container has writable temporary storage. Set the environment before starting the process or importing a library that may initialize Fontconfig, then run the failing operation and check its logs.
When Fontconfig Also Reports Configuration Errors
A cache-directory error can coexist with a configuration-parser failure, so changing ownership alone may not fix the application.
Treat messages such as these as a separate diagnostic branch:
unknown element "its:rules"
invalid attribute 'translate'
Cannot load config file from /etc/fonts/fonts.conf
Cannot load default config file
Library and Configuration Version Mismatches
An older bundled Fontconfig library may not understand configuration files supplied by a newer system installation.
A Magick.NET compatibility case involved Fontconfig 2.12.6 reading Ubuntu 20.04 configuration associated with Fontconfig 2.13.1. The workaround supplied matching older configuration files and selected their directory before image processing:
MagickNET.SetFontConfigDirectory("/etc/fonts/2.12");
That path must contain compatible configuration files and their required includes; creating an empty directory with that name does not fix anything.
Prefer updating the application’s native dependencies to a compatible set. If that is not possible, provide configuration compatible with the bundled library without replacing the host’s configuration globally. Restart the application afterward and confirm that both parser failures and cache-write errors are gone.
Command-Line Tools Work but the Application Still Fails
A successful system cache rebuild does not prove that a bundled library uses the same installation. The application may have a different Fontconfig version, configuration search path, or environment.
Compare the application’s debug output with the command-line tool’s output. Correct the application’s configuration location or update its native dependency package, then restart the application and repeat the original operation.
How to Verify the Fix and Keep It Working
Confirm the repair under the real application account and deployment settings:
- The intended cache directory exists and accepts a test write.
- The application loads the expected configuration without parser errors.
- A fresh application process completes the previously failing operation without the cache error.
- The generated output uses the expected fonts, not merely a visually plausible fallback.
A font-selection check can help:
fc-match sans-serif
This shows the font selected by the command-line Fontconfig installation. It checks font matching, not cache writability.
To prevent recurrence, keep cache ownership aligned with the runtime user, preserve necessary environment settings in the real launcher, and avoid running ordinary desktop applications as root. After changing a container user, volume mount, or service sandbox, rerun the original rendering operation under those new conditions.
Frequently Asked Questions
Does Debian 12 Need a Different Fontconfig Fix?
No. Debian 12 uses the same checks for the application’s account, environment, configuration, and cache permissions. If fc-cache is missing, install the command-line tools through the package manager:
sudo apt-get update
sudo apt-get install fontconfig
Then perform the cache repair and rebuild as the affected application’s user, not automatically as root. Installing the tools alone does not repair an unwritable home directory or container mount.
Can I Ignore the Error if My PDF or Image Still Renders?
Successful rendering does not prove that the cache is working: Fontconfig may still find fonts by scanning them or reading existing caches. The error can cause repeated scanning and noisy logs, and it may indicate that the runtime environment is misconfigured. Verify the actual output fonts and provide a writable cache rather than suppressing the message.
Why Do Newly Added Fonts Still Use a Fallback After the Cache Is Fixed?
A long-running rendering process may retain an in-memory font map even after the disk cache is rebuilt. Restart the process after installing fonts and rebuilding the cache, then render the output again. In sharp-based workflows, changing sharp’s image-cache setting is not equivalent to refreshing Fontconfig or Pango’s font state.
