How To Install Apt Get In Linux

How To Install Apt Get In Linux

Reading time1 min
#Linux#OpenSource#DevOps#APT#Debian#PackageManagement

How to Install and Configure APT-GET on Minimal Linux Distributions

Certain minimal Linux images—especially custom containers or trimmed VMs—come without apt-get. For system administrators maintaining uniform deployment tooling or DevOps pipelines, this breaks automation scripts. In these environments, bootstrapping APT can be essential.

Underlying Assumptions

APT is not a universal solution; it requires a Debian-based system with .deb packaging and the dpkg utility. On non-Debian distributions (e.g., Fedora, Arch, Alpine), implementation is non-trivial and rarely justified. The following applies to minimal Debian, Ubuntu, or derivatives, not to fundamentally incompatible bases.

1. Identify Your Environment

Immediate check—does your OS support APT at all?

cat /etc/os-release

Look for ID=debian or ID_LIKE=debian. Anything else, and you're out of scope.

2. Check for the dpkg Toolchain

APT is only a wrapper—dpkg does the real work. Some minimal installs exclude it.

which dpkg || echo 'dpkg not found'

If missing, manually download and extract the dpkg package:

wget http://ftp.us.debian.org/debian/pool/main/d/dpkg/dpkg_1.21.22_amd64.deb
ar x dpkg_1.21.22_amd64.deb
tar xf data.tar.xz -C /

(Version and architecture must match your base system. Failing to do so can brick the minimal instance: classic pitfall.)

If you get this type of error:

dpkg: command not found

continue extraction; if you see

dpkg: error: failed to open package info file '/var/lib/dpkg/status' for reading: No such file or directory

initialize the dpkg database:

mkdir -p /var/lib/dpkg
touch /var/lib/dpkg/status

3. Bootstrap APT

With dpkg operational, pull required APT binaries and dependencies:

wget http://ftp.us.debian.org/debian/pool/main/a/apt/apt_2.6.1_amd64.deb
dpkg -i apt_2.6.1_amd64.deb  # Will likely complain about missing dependencies.

If you see dependency errors such as:

dpkg: dependency problems prevent configuration of apt:
 apt depends on libapt-pkg6.0 (>= 2.6.0); however:
  Package libapt-pkg6.0 is not installed.

Manually fetch and install all required .deb files:

wget http://ftp.us.debian.org/debian/pool/main/a/apt/libapt-pkg6.0_2.6.1_amd64.deb
dpkg -i libapt-pkg6.0_2.6.1_amd64.deb
dpkg -i apt_2.6.1_amd64.deb

Repeat until all dependencies resolve (use ldd $(which apt-get) to check for missing shared libraries). There is no silver bullet here; dependencies change per Debian release.

4. Configure Apt Sources

Setup /etc/apt/sources.list minimally. For Debian 12 (“bookworm”):

cat > /etc/apt/sources.list <<EOF
deb http://deb.debian.org/debian bookworm main contrib non-free
deb http://security.debian.org/debian-security bookworm-security main contrib non-free
deb http://deb.debian.org/debian bookworm-updates main contrib non-free
EOF

Tip: The suite (bookworm, bullseye, etc.) must match your system (lsb_release -cs or /etc/os-release for codename).

5. Initialize APT and Test

Update and test. Expect GPG errors in minimal containers:

apt-get update

If you see:

E: Release file for ... is not signed yet

— temporarily append [trusted=yes] to each repo in sources.list. Not secure, but may be necessary for airgapped or ephemeral CI runners.

Install a test package, e.g., ca-certificates (also needed for HTTPS repos):

apt-get install ca-certificates -y

If apt self-updates, you’ve completed baseline bootstrapping.

Known Issues and Workarounds

  • Root Requirement: All apt operations require root or equivalent privileges. Sudo must be present, or operate as root directly.
  • Minimal Images May Lack Network Tools: Fetch dependencies before disconnecting from a management shell.
  • GPG/Keyring: For full security, install gnupg, debian-archive-keyring, and update trusted keys (apt-key is deprecated; use /etc/apt/trusted.gpg.d/).
  • Out-of-Sync Dependencies: Not all apt and dpkg versions are forward/backward compatible. Use dpkg --print-architecture before pulling binaries.

Example: Dockerfile Snippet for Minimal Debian

FROM debian:bookworm-slim

# Bootstrap essential tools
RUN apt-get update || ( \
    apt-get install -y wget ca-certificates && \
    wget ... && \
    dpkg -i ... )

# Continue container setup

Non-Trivial Tip

On some CI/CD runners, DNS resolution isn’t configured by default in minimal builds. Always validate /etc/resolv.conf before running apt-get update or you’ll get obscure “Temporary failure resolving” errors.


This installation process restores full APT package management capabilities on minimal Debian or Ubuntu-derived environments. In highly constrained setups, expect to repeat steps for every dependency. There is no shortcut.

Any edge cases (e.g., overlay filesystems, ro root) require further manual adjustment or pre-seeding via chrooted environments.