How to fix E: Package 'vim' has no installation candidate in Docker

DockerBEGINNERMEDIUMUpdated Dec 6, 2025ยท 191 views

This error occurs during Docker image builds when apt-get cannot find a valid version of the requested package to install. The most common fix is running apt-get update before installation to refresh the package index.

Quick fix

Fixes E: Package 'vim' has no installation candidate

FROM ubuntu:22.04

# Wrong - Missing apt-get update
RUN apt-get install -y vim

# Correct - Update package index first
RUN apt-get update && apt-get install -y vim
  1. Run apt-get update before installation
  2. Combine update and install in a single RUN command
  3. Enable additional repositories (universe/multiverse)
  4. Verify package availability for your base image
docker โ€” error
FROM ubuntu:22.04
# Wrong - Missing apt-get update
RUN apt-get install -y vim
# Correct - Update package index first
RUN apt-get update && apt-get install -y vim
E: Package 'vim' has no installation candidate

What this error means

The "Package has no installation candidate" error appears when the APT package manager knows a package exists (it's referenced somewhere) but cannot find a downloadable version in any configured repository. Unlike "Unable to locate package" which means APT has never heard of the package, this error indicates APT has some metadata about the package but no actual installation files are available. In Docker containers, this typically happens because base images ship with minimal or completely empty package indexes to reduce image size. When you run `apt-get install` without first running `apt-get update`, APT either has no package index at all or has a stale index that references packages that have been moved, renamed, or removed from the repositories. This is especially common with packages that exist in specific repositories (like "universe" or "multiverse" in Ubuntu) that may not be enabled by default in minimal Docker images.

Typical symptoms

  • Build fails with 'E: Package '<package>' has no installation candidate'
  • apt-get install fails even though apt list shows the package exists
  • Package installation works on host machine but fails inside Docker container
  • Error appears for common packages like vim, nano, or development tools
  • Same Dockerfile worked in the past but now fails after base image update

Common causes

  1. Missing apt-get update before apt-get install in Dockerfile
  2. Package index is empty or stale in the Docker base image
  3. Package exists only in 'universe' or 'multiverse' repository which is not enabled
  4. Package name has changed or been deprecated in newer Ubuntu/Debian versions
  5. apt-get update and apt-get install in separate RUN commands causing cached stale index
  6. Using an outdated or minimal base image that excludes certain repositories

How to fix "E: Package 'vim' has no installation candidate"

1Run apt-get update before installation

The most common fix is to refresh the package index before installing. Always combine apt-get update with apt-get install in the same RUN command:

dockerfile
FROM ubuntu:22.04

# Wrong - Missing apt-get update
RUN apt-get install -y vim

# Correct - Update package index first
RUN apt-get update && apt-get install -y vim

The && operator ensures both commands run in sequence and if update fails, installation won't proceed. This prevents Docker from using a cached (stale) package index from a previous build layer.

2Combine update and install in a single RUN command

If you have apt-get update and apt-get install in separate RUN commands, Docker caches each layer independently. This means a cached update can become stale:

dockerfile
# Wrong - Separate RUN commands (update gets cached)
RUN apt-get update
RUN apt-get install -y vim  # May fail if update layer is cached

# Correct - Single RUN command
RUN apt-get update && apt-get install -y \
    vim \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

The rm -rf /var/lib/apt/lists/* at the end removes the package cache to reduce image size.

3Enable additional repositories (universe/multiverse)

Some packages are only available in additional Ubuntu repositories. If the package isn't in the main repository, enable universe or multiverse:

dockerfile
FROM ubuntu:22.04

# Enable universe repository for additional packages
RUN apt-get update && \
    apt-get install -y software-properties-common && \
    add-apt-repository universe && \
    apt-get update && \
    apt-get install -y <package-name>

Alternatively, manually edit sources.list:

dockerfile
RUN echo "deb http://archive.ubuntu.com/ubuntu/ jammy main universe" > /etc/apt/sources.list && \
    echo "deb http://archive.ubuntu.com/ubuntu/ jammy-updates main universe" >> /etc/apt/sources.list && \
    apt-get update && \
    apt-get install -y <package-name>
4Verify package availability for your base image

The package may not exist in your Ubuntu/Debian version. Check availability by running a temporary container:

bash
# Start temporary container with your base image
docker run -it --rm ubuntu:22.04 bash

# Inside container, update and search for package
apt-get update
apt-cache search vim
apt-cache policy vim

The apt-cache policy <package> command shows available versions and which repository provides them. If nothing appears, the package doesn't exist in that distro version.

For packages that have been renamed or removed, search online for alternatives or use a different base image:

dockerfile
# Python 2 removed from newer Ubuntu - use older image
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y python2
5Force rebuild without cache

If you suspect Docker is using cached layers with stale package indexes, rebuild without cache:

bash
# Rebuild image without using cache
docker build --no-cache -t myimage .

# Or pull fresh base image first
docker pull ubuntu:22.04
docker build --no-cache -t myimage .

This forces Docker to run all commands fresh, including apt-get update, ensuring the latest package index is downloaded.

Advanced notes

Understanding the difference between apt errors: "Unable to locate package" means APT has no knowledge of the package at all. "Package has no installation candidate" means APT knows the package exists (often because another package depends on it) but cannot find installable files. Both typically resolve with apt-get update.

Minimal vs full base images: Images like ubuntu:22.04 are intentionally minimal. They may not include all repository definitions. Consider using buildpack-deps:jammy or similar images that come with common development packages pre-installed.

Debian vs Ubuntu repositories: Debian-based images (like debian:bookworm) have different repository names (main, contrib, non-free). Make sure you're using the correct repository syntax for your base image.

DEBIAN_FRONTEND=noninteractive: Some packages prompt for configuration during installation. Set this environment variable to prevent interactive prompts that would hang Docker builds:

dockerfile
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y tzdata

Using aptitude for dependency resolution: In rare cases, aptitude can resolve complex dependency issues better than apt-get:

dockerfile
RUN apt-get update && \
    apt-get install -y aptitude && \
    aptitude install -y problematic-package

Network/mirror issues: If apt-get update itself fails, you may be hitting rate limits or network issues. Try specifying a different mirror or check if you're behind a corporate proxy that blocks apt repositories.

Frequently asked questions

What does "E: Package 'vim' has no installation candidate" mean?
The "Package has no installation candidate" error appears when the APT package manager knows a package exists (it's referenced somewhere) but cannot find a downloadable version in any configured repository. Unlike "Unable to locate package" which means APT has never heard of the package, this error indicates APT has some metadata about the package but no actual installation files are available. In Docker containers, this typically happens because base images ship with minimal or completely empty package indexes to reduce image size.
How do I fix "E: Package 'vim' has no installation candidate"?
This error occurs during Docker image builds when apt-get cannot find a valid version of the requested package to install. The most common fix is running apt-get update before installation to refresh the package index.
What causes "E: Package 'vim' has no installation candidate"?
Missing apt-get update before apt-get install in Dockerfile Package index is empty or stale in the Docker base image Package exists only in 'universe' or 'multiverse' repository which is not enabled
Is the "E: Package 'vim' has no installation candidate" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading