How to Install a .deb File on Ubuntu and Debian

How to Install a .deb File on Ubuntu and Debian

Reading time1 min
#Linux#Ubuntu#Debian#DEB#PackageManagement

How to Install a .deb File on Ubuntu and Debian

A .deb file is a software package for Debian, Ubuntu, Linux Mint, Pop!_OS and other Debian-based distributions. It contains the program's files plus metadata: package name, version, CPU architecture, dependencies and maintainer scripts that run during installation.

You do not "run" or "open" a .deb the way you run an .exe on Windows. You install it with the package manager, and then you run the program it installed.

If the software is available in your distribution's repositories, sudo apt install name is still the better choice, because it then gets security updates together with the rest of the system. A downloaded .deb makes sense when the vendor only ships it that way.

Install with apt (recommended)

cd ~/Downloads
sudo apt update
sudo apt install ./my-app_1.2.3_amd64.deb

The ./ matters. With a path (anything containing a slash), apt treats the argument as a local file. Without it, apt searches the repositories for a package literally named my-app_1.2.3_amd64.deb and fails with "Unable to locate package".

apt reads the dependency list from the file and installs whatever is missing from your configured repositories. That is why apt update first is a good habit.

You may see this notice:

N: Download is performed unsandboxed as root as file '/home/user/Downloads/my-app_1.2.3_amd64.deb' couldn't be accessed by user '_apt'.

It is harmless. apt normally downloads as the unprivileged _apt user, which cannot read your home directory, so it falls back to root. The package is still installed.

Several files at once work too, and apt resolves dependencies between them:

sudo apt install ./*.deb

apt-get install ./file.deb behaves the same way. Prefer apt-get in scripts, since apt is meant for interactive use and its output can change between versions.

Install with dpkg

dpkg is the low-level tool underneath apt. It installs exactly the file you give it and never downloads dependencies.

sudo dpkg -i my-app_1.2.3_amd64.deb

If a dependency is missing, dpkg unpacks the package but leaves it unconfigured with "dependency problems, leaving unconfigured". Let apt finish the job:

sudo apt --fix-broken install    # same as: sudo apt-get install -f

apt then installs the missing dependencies and configures the package, or offers to remove it if the dependencies cannot be satisfied. Read the plan it prints before you confirm.

Use dpkg -i directly when you are offline and already have every dependency as a .deb in the same directory (sudo dpkg -i *.deb), or when you are debugging a package.

Install from the desktop

On Ubuntu 24.04 and later, double-click the file or right-click it and choose Open With, App Center. The first 24.04 release could not do this; a later App Center update added it back (sudo snap refresh snap-store if yours still refuses). App Center warns that the package comes from a third party, which is accurate.

gdebi is an older lightweight installer that also resolves dependencies. It is no longer needed since apt handles local files, but it still works:

sudo apt install gdebi-core
sudo gdebi my-app_1.2.3_amd64.deb

Check the file before installing

A package installs as root, and its maintainer scripts run as root. Treat a downloaded .deb like any script you would run with sudo.

sha256sum my-app_1.2.3_amd64.deb      # compare with the checksum on the vendor's site
dpkg-deb -I my-app_1.2.3_amd64.deb    # name, version, Architecture, Depends
dpkg-deb -c my-app_1.2.3_amd64.deb    # files it will install
dpkg --print-architecture             # your system: amd64, arm64, ...

The package architecture must match yours or be all. "package architecture (arm64) does not match system (amd64)" means you downloaded the wrong build. Get the right one instead of forcing it.

Also look at Depends. A package built for a newer release can require library versions your system does not have. Pick the build for your release (cat /etc/os-release shows it).

Open a .deb without installing it

A .deb is an ar archive with three members: debian-binary, control.tar.* (metadata and scripts) and data.tar.* (the actual files).

dpkg-deb -x my-app_1.2.3_amd64.deb ./my-app-files      # extract the payload
dpkg-deb -e my-app_1.2.3_amd64.deb ./my-app-control    # extract control file and scripts
less ./my-app-control/postinst                         # what runs as root after install

On a system without dpkg, use ar and tar:

ar x my-app_1.2.3_amd64.deb
tar -xf data.tar.*

Recent Ubuntu packages are compressed with zstd, so tar needs the zstd tool installed to unpack data.tar.zst.

There is no supported way to install a .deb on Fedora, RHEL or Arch. Look for an .rpm, a Flatpak or a tarball from the same vendor instead.

Run the program after installing

Find the package name inside the file, then list what it installed:

dpkg-deb -f my-app_1.2.3_amd64.deb Package    # package name, e.g. my-app
dpkg -L my-app | grep -E '/s?bin/'            # installed executables

Desktop applications add a .desktop file under /usr/share/applications, so they appear in the app menu. Command-line tools usually land in /usr/bin and run by name. Some vendors install into /opt/vendor-name/ and add a symlink.

Updates

A .deb you installed by hand does not update itself unless the package also added a repository. Many vendors (browsers, editors, VPN clients) drop an apt source into /etc/apt/sources.list.d/ during installation, and from then on sudo apt upgrade keeps them current.

ls /etc/apt/sources.list.d/
apt policy my-app

If apt policy lists only /var/lib/dpkg/status as a source, no repository provides the package. Download the newer .deb and install it the same way: apt upgrades it in place.

Remove a package

sudo apt remove my-app      # keeps configuration files in /etc
sudo apt purge my-app       # removes configuration files too
sudo apt autoremove         # removes dependencies nothing else needs

Use the package name, not the file name. dpkg -l | grep my-app shows the exact name and version.

Troubleshooting

  • "Unable to locate package my-app.deb": the ./ or full path is missing.
  • "dpkg was interrupted, you must manually run 'sudo dpkg --configure -a'": run it, then sudo apt --fix-broken install.
  • "Could not get lock /var/lib/dpkg/lock-frontend": another apt process is running, often unattended-upgrades right after boot. Wait for it to finish. Do not delete lock files.
  • "Depends: libfoo (>= 2.0) but it is not installable": the package was built for a different release. Get the matching build or use the vendor's repository, Snap or Flatpak.
  • "trying to overwrite '/usr/bin/foo', which is also in package bar": two packages ship the same file. Remove the conflicting one. Avoid --force-overwrite and --force-all, which leave the package database inconsistent.

Scripts and Dockerfiles

apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y ./my-app_1.2.3_amd64.deb

DEBIAN_FRONTEND=noninteractive stops configuration prompts from hanging an unattended run. Run it as root, or put sudo in front.

Quick reference

sudo apt install ./file.deb               # install with dependencies
sudo dpkg -i file.deb                     # low-level install, no dependency resolution
sudo apt --fix-broken install             # finish a dpkg install with missing dependencies
dpkg-deb -I file.deb                      # package metadata
dpkg-deb -c file.deb                      # list files
dpkg-deb -x file.deb ./dir                # extract without installing
dpkg -L package-name                      # files of an installed package
apt policy package-name                   # installed version and where updates come from
sudo apt remove package-name              # uninstall (purge also removes config)