582

Say, I have foo-1.2.3.deb which depends on perl and python, however, running command:

dpkg -i ./foo-1.2.3.deb

won't install these dependencies. So I must apt-get install perl python by hand.

How to make dpkg -i install these dependencies for me automatically?

Jorge Castro
  • 71,754
Lenik
  • 10,398

12 Answers12

718

After using dpkg, running the following command helped me to install the required dependencies:

sudo apt-get -f install

In all, your terminal should look like this:

$ sudo dpkg -i package_with_unsatisfied_dependencies.deb
dpkg: dependency problems prevent ... 
[additional messages]

$ sudo apt-get -f install
[apt messages]
Setting up [dependency]...
Setting up package_with_unsatisfied_dependencies...

Notice the line about Setting up package_with_unsatisfied_dependencies. This fixes (and completes) the installation of package_with_unsatisfied_dependencies.deb.

galoget
  • 2,963
Arindom
  • 8,182
  • 20
    Should I run sudo dpkg -i mypackage.deb again ? – Muhammad Gelbana Nov 22 '13 at 13:41
  • 50
    After running sudo apt-get -f install my package and it's dependencies were all installed. Running sudo dpkg -i my_package.deb is unnecessary and will just install the package again. – Gus E Dec 13 '13 at 16:20
  • 9
    Following works on Ubuntu 14.04: sudo dpkg -i package.deb; sudo apt-get -f install; sudo dpkg -i package.deb. The first dpkg -i run marks dependencies, apt-get -f install installs required dependencies and the second dpkg -isuccessfully installs the package. Note that apt-get install -f is totally different command. – Mikko Rantalainen Apr 21 '16 at 11:19
  • 2
    @ysth no, do not do dpkg -i --force; that will force-install a broken package! Running dpkg /without/ --force will make the necessary entry in the package database so that apt-get -f install will do the right thing. – Brian A. Henning May 10 '16 at 15:21
  • @Lotharyx: I can't try it right now, but I didn't think the dpkg without force (that fails due to missing dependencies) would make an entry in the package database – ysth May 10 '16 at 17:00
  • @ysth It does. I did try it. YMMV. – Brian A. Henning May 10 '16 at 21:44
  • @MikkoRantalainen are really apt-get -f install and apt-get install -f different? Here it's said they're the same. – Arch Stanton Jan 16 '18 at 15:31
  • what if I don't have apt-get installed ? I need to solve dependencies solely on dpkg – moth Jun 04 '21 at 12:59
  • -f stands for --fix-broken. – Константин Ван Feb 08 '23 at 15:37
  • This solution isn't working for me since it also automatically install the most recent version of the package, hence instead of having foo-1.2.3 I end up having foo-2.0.0 and it's not what I was looking for. – M.Liscio Jan 05 '24 at 10:37
264

starting with apt 1.1 (available in Xenial (16.04), stretch) apt install also allows local files:

sudo apt install ./foo-1.2.3.deb

So much simpler and cleaner.

See the release announcment

Zanna
  • 70,465
textshell
  • 2,741
121

You can install gdebi-core, which is the command line version of the GDebi package installer from 10.04 and earlier. In the newer versions of Ubuntu, the Software Center is used to install debs, which doesn't have a command line equivalent.

To install a deb package using gdebi, just run:

sudo gdebi my_package_1.0.deb
44

Gdebi

gdebi installs a deb package and its dependencies. To use it run:

sudo gdebi package.deb

In newer versions of Ubuntu, this is not installed by default, so you will need to install it from the repositories.

See man gdebi for a full list of options.

gdebi is the command line equivalent to the graphical tool of the same name that used to be included by default in Ubuntu. The command for the graphical tool is gdebi-gtk and has similar functionality:

gdebi-gtk

dv3500ea
  • 37,204
  • gdebi-gtk wont show required deps (the version I have here at least, and it looks like a bug), but the command line will! If we have another machine with the packages we can use dpkg-repack on it based on such deps list :) – Aquarius Power Jul 13 '18 at 21:37
22

running

sudo apt-get install -f

after installing package with dpkg may solve broken depencies (at least man apt-get say so...). Ill update when i will check it.

Denwerko
  • 1,218
17

If you need to run a command that automatically resolves all of a .deb file's dependencies and installs the .deb file and its missing dependencies with the same command, you will need to update your installed software with sudo apt update. Then open the terminal, change directories using cd to the directory containing package-name.deb, and type:

apt install --simulate ./package-name.deb # This command does not require sudo.

where package-name.deb should be replaced by the name of a .deb file located in the current directory that you are trying to install.

The above command will not install anything, but it will print a message listing any dependencies of package-name.deb that do not exist in the default Ubuntu repositories. You will need to manually download and install the .deb files of these missing dependency packages in order to install package-name.deb. Run apt install --simulate ./manually-downloaded-package.deb before installing any of these manually downloaded dependency packages in order to check if these packages have any unmet dependencies themselves.

If the simulated command completes successfully, run the following command to install package-name.deb.

sudo apt install ./package-name.deb

There can be multiple .deb files in the same command if the .deb files are all located in the current directory.

sudo apt install ./package-name-1.deb ./package-name-2.deb
karel
  • 114,770
11

dpkg doesn't have dependency support. There is a way around it but that would require you to make a local database (and thus you would already know the dependencies) and it is considered obsolete (...).

Does it have to be command line? (server install?) If so also have a look at apt-get -f but be careful: solving dependencies after install could have you end up with a broken system.

gdebi (gui frontend) used to be able to do this but got replaced with USC.

How did you download the .deb. Some of the new 11.04 features is the handling of .deb downloaded from a website: it gets opend in USC so dependencies will be solved by the installer.

EDIT based on comment by andrew: sudo gdebi foo-1.2.3.deb would do the trick!!

Rinzwind
  • 299,756
4

You could create a file dpkg-dep-inst with the following content.

#!/bin/bash

DEBIAN_FILE1=$1
dpkg -i $DEBIAN_FILE1 || apt-get --fix-broken install

I assume you created the file in your home folder. Make it executable with chmod +x dpkg-dep-inst and move it to /usr/local/bin with sudo cp dpkg-dep-inst /usr/local/bin.

Now you can install the debian package with dependencies automatically with:

sudo dpkg-dep-inst foo-1.2.3.deb
vdegenne
  • 205
BuZZ-dEE
  • 14,223
3

As an alternative to gdebi-gtk you can use Ubuntu Software Center.

Double click on the package and an install button should be available.

heemayl
  • 91,753
2

The below command will attempt to correct any dependency issues

sudo apt-get install -f

So it's good practice to run that after installing a package

sudo dpkg -i YOUR-PACKAGE.deb && sudo apt-get install -f

2

I just ran into this problem. Calling apt-get install -f will not install recommended dependencies, though! The only workaround for this would be then to create a local repository and add to /etc/apt/sources.list, i.e.:

apt-ftparchive packages . > Packages && gzip < Packages > Packages.gz
sudo echo "deb file://$PWD /" >> /etc/apt/sources.list
sudo apt-get update
1

Actually the answer is that dpkg package manager cannot install dependencies out of the box. You cam man dpkg and found that out. So you need to use tools like apt, apt-get, aptitude, ..., based on dpkg.

I would say just the same case is for the rpm package manager on the other Linux hemisphere. rmp is not meant to do dependency based installs. It can install single packages, and for installing the dependencies you use yum, urpmi, up2date these are all based on RPM.

As noted there is a slight danger installing packages with dpkg directly, because later dependency resolution resolving may end up with a broken system as @Rinzwind outlined.

prosti
  • 1,017