How to fix E: Unable to write to /var/cache/apt/ in 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.
Quick fix
Fixes E: Unable to write to /var/cache/apt/
sudo apt update
sudo apt install <package-name>- Use sudo to run apt commands
- Check if another apt process is running
- Remove lock files if no apt process is running
- Check filesystem status if read-only error appears
sudo apt updatesudo 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
- 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
- Corrupted or incomplete package cache from interrupted operations
- Filesystem permissions on /var/cache/apt/ are incorrect
How to fix "E: Unable to write to /var/cache/apt/"
The most common cause is running apt without administrative privileges. Always prefix apt commands with sudo:
sudo apt update
sudo apt install <package-name>Apt requires root permissions to write to system directories like /var/cache/apt/.
If using sudo does not resolve the issue, check if another package manager instance is currently running:
ps aux | grep -i aptIf 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.
If no apt process is running but lock files remain, remove them:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lockThen reconfigure the package database:
sudo dpkg --configure -aIf the error message includes "Read-only file system", run a filesystem check:
sudo touch /var/cache/apt/test-fileIf this fails with read-only error, your filesystem needs repair. Reboot into recovery mode or use a live USB, then run:
sudo fsck -y /dev/sdXnReplace /dev/sdXn with your actual partition. After repair, reboot and verify apt works.
If your cache is corrupted from an interrupted operation:
sudo rm -rf /var/lib/apt/lists/*
sudo mkdir -p /var/lib/apt/lists/partial
sudo apt updateThis removes all cached package lists and rebuilds them from repositories.
If issues persist, verify the cache directory ownership:
ls -la /var/cache/apt/The directory should be owned by root. If not, fix permissions:
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
- ๐APT Official Documentation
- ๐Ubuntu Wiki - Debugging Installation Issues(Official Docs)
- ๐Ubuntu Manual - apt-cache(Official Docs)