How to fix E: Unable to write to /var/cache/apt/ in APT

APTBEGINNERMEDIUMUpdated Dec 29, 2025ยท 224 views

This error occurs when apt lacks write permissions to its cache directory, typically caused by read-only filesystem, permission issues, or running apt without sudo. The fix involves checking filesystem status, using sudo, or clearing lock files.

Quick fix

Fixes E: Unable to write to /var/cache/apt/

sudo apt update
sudo apt install <package-name>
  1. Use sudo to run apt commands
  2. Check if another apt process is running
  3. Remove lock files if no apt process is running
  4. Check filesystem status if read-only error appears
apt โ€” error
sudo apt update
sudo apt install <package-name>
E: Unable to write to /var/cache/apt/

What this error means

The "Unable to write to /var/cache/apt/" error indicates that the apt package manager cannot create, modify, or access files in the /var/cache/apt/ directory. This directory is essential for apt to store downloaded packages, metadata, and lock files. When apt cannot write to this location, it cannot proceed with package updates or installations. The error typically stems from three sources: insufficient user permissions (running apt without sudo), a read-only filesystem state, or competing apt processes holding lock files.

Typical symptoms

  • apt update, apt install, or apt-get commands fail immediately
  • Permission denied errors appear when trying to update the package cache
  • Software updates cannot be downloaded to the cache directory
  • Error messages mention "Read-only file system" alongside the cache error

Common causes

  1. Running apt or apt-get commands without sudo privileges
  2. Filesystem is mounted as read-only (often after a filesystem error or crash)
  3. Lock files in /var/cache/apt/ are held by another apt process
  4. Corrupted or incomplete package cache from interrupted operations
  5. Filesystem permissions on /var/cache/apt/ are incorrect

How to fix "E: Unable to write to /var/cache/apt/"

1Use sudo to run apt commands

The most common cause is running apt without administrative privileges. Always prefix apt commands with sudo:

bash
sudo apt update
sudo apt install <package-name>

Apt requires root permissions to write to system directories like /var/cache/apt/.

2Check if another apt process is running

If using sudo does not resolve the issue, check if another package manager instance is currently running:

bash
ps aux | grep -i apt

If you see an apt or apt-get process, wait for it to complete. You can also check if the Software Update manager is open and close it before trying again.

3Remove lock files if no apt process is running

If no apt process is running but lock files remain, remove them:

bash
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

Then reconfigure the package database:

bash
sudo dpkg --configure -a
4Check filesystem status if read-only error appears

If the error message includes "Read-only file system", run a filesystem check:

bash
sudo touch /var/cache/apt/test-file

If this fails with read-only error, your filesystem needs repair. Reboot into recovery mode or use a live USB, then run:

bash
sudo fsck -y /dev/sdXn

Replace /dev/sdXn with your actual partition. After repair, reboot and verify apt works.

5Clear corrupted cache and rebuild

If your cache is corrupted from an interrupted operation:

bash
sudo rm -rf /var/lib/apt/lists/*
sudo mkdir -p /var/lib/apt/lists/partial
sudo apt update

This removes all cached package lists and rebuilds them from repositories.

6Verify permissions on cache directories

If issues persist, verify the cache directory ownership:

bash
ls -la /var/cache/apt/

The directory should be owned by root. If not, fix permissions:

bash
sudo chown -R root:root /var/cache/apt/
sudo chmod -R 755 /var/cache/apt/

Then retry your apt command.

Advanced notes

In containerized environments (Docker), this error commonly occurs when running apt without sudo inside the container, even though root is the default user. Explicitly use RUN apt-get (not apt) in Dockerfiles and ensure the base image has apt installed. In WSL (Windows Subsystem for Linux), the error can occur after ungraceful shutdown; run wsl --shutdown on Windows, then reopen WSL. On systems with automounted read-only /var/cache partitions (rare), check /etc/fstab for ro flags and remount with sudo mount -o remount,rw /var/cache. If you frequently encounter this, consider using apt-cacher-ng to cache packages locally on your network.

Frequently asked questions

What does "E: Unable to write to /var/cache/apt/" mean?
The "Unable to write to /var/cache/apt/" error indicates that the apt package manager cannot create, modify, or access files in the /var/cache/apt/ directory. This directory is essential for apt to store downloaded packages, metadata, and lock files. When apt cannot write to this location, it cannot proceed with package updates or installations.
How do I fix "E: Unable to write to /var/cache/apt/"?
This error occurs when apt lacks write permissions to its cache directory, typically caused by read-only filesystem, permission issues, or running apt without sudo. The fix involves checking filesystem status, using sudo, or clearing lock files.
What causes "E: Unable to write to /var/cache/apt/"?
Running apt or apt-get commands without sudo privileges Filesystem is mounted as read-only (often after a filesystem error or crash) Lock files in /var/cache/apt/ are held by another apt process
Is the "E: Unable to write to /var/cache/apt/" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading