This error occurs when apt lacks permission to access or create the /var/lib/apt/lists/partial directory, commonly in Docker containers or when running apt as a non-root user. The fix involves recreating the directory structure and updating the package cache with proper permissions.
The apt package manager stores metadata about available packages in /var/lib/apt/lists. The partial subdirectory is used as a temporary staging area during downloads. When apt cannot create or access this directory due to insufficient permissions (error code 13), it fails to update the package cache. This typically happens because the command is running with insufficient privileges or in a restricted environment like Docker containers where the filesystem permissions are not properly configured.
First, verify whether you are running the command with proper privileges:
whoamiIf the output is not "root" and you are on a standard Linux system (not in a container), you need to use sudo with apt commands.
Delete all files in the /var/lib/apt/lists directory to clear any corrupted package metadata:
sudo rm -rf /var/lib/apt/lists/*This command removes all cached package information, which will be rebuilt in the next step.
Create the necessary directory structure with proper permissions:
sudo mkdir -p /var/lib/apt/lists/partialThe -p flag ensures parent directories are created if they do not exist.
Clean the apt cache and rebuild it by running update:
sudo apt-get clean
sudo apt-get updateThe clean command removes unnecessary files, and update rebuilds the package index from configured repositories.
If you are building a Docker image, ensure all apt operations occur before switching to a non-root user:
FROM ubuntu:22.04
# Run apt operations as root
RUN apt-get update && apt-get install -y curl wget
# Switch to non-root user after apt operations
RUN useradd -m appuser
USER appuserThe key is to keep apt-get update and apt-get install commands before the USER instruction.
In Debian and newer Ubuntu releases, the apt package manager uses a dedicated "_apt" user for sandboxed downloads. If you see warnings about "_apt" user not being able to access files, you can fix ownership with: sudo chown -R _apt:root /var/lib/apt/lists/partial. Additionally, if using Docker, be aware that the package lists are large and rebuilding them on every container restart can slow down image builds. Consider using a multi-stage build or caching the apt-get update in your Docker layer.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT