How to fix dpkg: error: unable to create new file 'path': Permission denied in APT

APTBEGINNERMEDIUMUpdated Dec 29, 2025ยท 379 views

The "dpkg: error: unable to create new file: Permission denied" error occurs when your user account lacks sufficient permissions to modify package management directories. This is almost always resolved by running the command with sudo privileges.

Quick fix

Fixes dpkg: error: unable to create new file 'path': Permission denied

sudo apt update
sudo apt install package-name
sudo apt upgrade
sudo dpkg -i package.deb
  1. Use sudo for package management commands
  2. Check for running package manager processes
  3. Remove stale lock files
  4. Fix directory ownership and permissions
apt โ€” error
sudo apt update
sudo apt install package-name
sudo apt upgrade
sudo dpkg -i package.deb
dpkg: error: unable to create new file 'path': Permission denied

What this error means

When you run a dpkg or apt command, the package manager needs to write files to protected system directories like /var/lib/dpkg, /var/cache/apt, and /usr. If your user account doesn't have permission to write to these directories, dpkg fails to create necessary files during installation or configuration. This error typically appears when: - A non-root user runs apt/dpkg commands without sudo - The /var/lib/dpkg directory has incorrect ownership - Lock files are preventing normal package operations - Another process is already using the package manager The error message includes the specific file path that dpkg couldn't create, helping you identify which system directory has permission issues.

Typical symptoms

  • apt/apt-get/dpkg commands fail immediately with 'Permission denied'
  • Software Center or Synaptic package manager appears to be updating indefinitely
  • Unable to install, upgrade, or remove any packages via command line
  • Error mentions /var/lib/dpkg/, /var/cache/apt/, or /usr/ directories
  • Running the same command with sudo works without errors

Common causes

  1. Running apt/dpkg commands without sudo when the user lacks permissions to system directories
  2. Another package manager or system update process is holding a lock on the dpkg database
  3. Incorrect ownership or permissions on /var/lib/dpkg or /var/cache/apt directories
  4. Stale lock files remaining from a previous interrupted installation
  5. Read-only filesystem mounted or insufficient disk space in /var

How to fix "dpkg: error: unable to create new file 'path': Permission denied"

1Use sudo for package management commands

The simplest and most common fix is to run your command with sudo prefix:

bash
sudo apt update
sudo apt install package-name
sudo apt upgrade
sudo dpkg -i package.deb

This grants the necessary root privileges to modify protected system directories. If you forget sudo and the command fails, just rerun it with sudo.

2Check for running package manager processes

If you already used sudo but still see the error, another package manager might be using dpkg. Check for active processes:

bash
sudo lsof /var/lib/dpkg/lock-frontend
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lock

If any processes are listed, they must complete first. If you see a process that shouldn't be running, you can kill it:

bash
sudo kill -9 <PID>

Common culprits include Software Center, Software Updater, Synaptic, or unattended-upgrades.

3Remove stale lock files

If no processes are using dpkg but lock files still exist, they may be stale from an interrupted operation. Remove them:

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

After removing lock files, reconfigure dpkg:

bash
sudo dpkg --configure -a
sudo apt update

This forces dpkg to check and complete any pending operations.

4Fix directory ownership and permissions

If the problem persists, the /var/lib/dpkg or /var/cache/apt directories may have incorrect ownership. Restore proper permissions:

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

Then try your package operation again:

bash
sudo apt update

This ensures these critical directories are owned by root and have the correct read/write/execute permissions.

5Clean up partial packages and retry

If you've had interrupted downloads, clean the cache and start fresh:

bash
sudo apt clean
sudo apt autoclean
sudo apt update
sudo apt install package-name

The apt clean command removes all cached .deb files, while autoclean removes only outdated ones. This resolves issues with corrupted or incomplete package downloads.

6Check filesystem and disk space

In rare cases, the error occurs if /var is mounted read-only or if the disk is full:

bash
df -h /var
mount | grep "on /var"

If /var is full, delete old log files:

bash
sudo journalctl --vacuum=50M
sudo rm /var/log/*.old

If /var is mounted read-only, remount it as read-write:

bash
sudo mount -o remount,rw /var

Advanced notes

SELinux and AppArmor: On systems with SELinux or AppArmor enabled, package manager operations may be blocked by security policies even with proper file permissions. If the above steps don't work, check if SELinux/AppArmor is denying access: sudo grep -i denied /var/log/audit/audit.log for SELinux or check AppArmor logs. You may need to temporarily disable these security frameworks while troubleshooting.

Rootless containers: If you're in a Docker container or Kubernetes pod running as a non-root user, you cannot use apt/dpkg directly. These tools require root. Either run the container as root or install packages in your Dockerfile during the build stage.

WSL2 (Windows Subsystem for Linux): On WSL2, ensure your /var partition has adequate disk space. The WSL2 virtual disk can become full, causing these errors. Run wsl --manage to clean up the virtual disk.

VPS/Cloud instances: Some cloud providers mount /var as read-only by default for system integrity. Contact your provider's support to have it remounted as read-write, or ask if they provide automated package management tools.

Frequently asked questions

What does "dpkg: error: unable to create new file 'path': Permission denied" mean?
When you run a dpkg or apt command, the package manager needs to write files to protected system directories like /var/lib/dpkg, /var/cache/apt, and /usr. If your user account doesn't have permission to write to these directories, dpkg fails to create necessary files during installation or configuration. This error typically appears when: - A non-root user runs apt/dpkg commands without sudo - The /var/lib/dpkg directory has incorrect ownership - Lock files are preventing normal package operations - Another process is already using the package manager The error message includes the specific file path that dpkg couldn't create, helping you identify which system directory has permission issues.
How do I fix "dpkg: error: unable to create new file 'path': Permission denied"?
The "dpkg: error: unable to create new file: Permission denied" error occurs when your user account lacks sufficient permissions to modify package management directories. This is almost always resolved by running the command with sudo privileges.
What causes "dpkg: error: unable to create new file 'path': Permission denied"?
Running apt/dpkg commands without sudo when the user lacks permissions to system directories Another package manager or system update process is holding a lock on the dpkg database Incorrect ownership or permissions on /var/lib/dpkg or /var/cache/apt directories
Is the "dpkg: error: unable to create new file 'path': Permission denied" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading