Automatically install dependencies with “dpkg -i”

By neokrates, written on July 19, 2010

bash   snippet

  • Join date: 11-30-99
  • Posts: 224
View Counter:
  • 5,312 views
Rate it
Ad
Poll
  • Trend: what general purpose computer language will dominate IT industry in the next decade?

    View Results

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext

Here is a combination of dpkg -i and apt-get -f install which will install a package and its dependencies automatically

This snippet will only work if you Linux distro knows how to get all packages, which are required.

Works for:

✔ Debian Lenny

✔ Apt-get

✔ dpkg

Should also work for:

✔ any Linux distro

Generally, you do:
1. dpkg -i
2. If it needs dependencies, get them automatically with apt-get-f --force-yes --yes install.

👉 dpkg -i has generated the list of unresolved dependencies, apt-get -f will just pick it up.

3. Run the dpkg -i again

Example:
I have git_1.7.1-1_i386.deb and git-core_1.7.1-1_all.deb, which allow me to get newest git on my Debian Lenny.
The problem is, if I do dpkg -i git_1.7.1-1_i386.deb it complains about missing packages libcurl3-gnutls liberror-perl libdigest-sha1-perl:

# dpkg -i git_1.7.1-1_i386.deb
Selecting previously deselected package git.
	(Reading database ... 36488 files and directories currently installed.)
		Unpacking git (from tools/scm/git_1.7.1-1_i386.deb) ...
		dpkg: dependency problems prevent configuration of git:
	git depends on libcurl3-gnutls (>= 7.16.2-1); however:
		Package libcurl3-gnutls is not installed.
	git depends on liberror-perl; however:
		Package liberror-perl is not installed.
	git depends on libdigest-sha1-perl; however:
		Package libdigest-sha1-perl is not installed.
	dpkg: error processing git (--install):
		dependency problems - leaving unconfigured
	Processing triggers for man-db ...
		Errors were encountered while processing:
git

 

To get the installation automatically on any similar System, I wrote this script:

dpkg -i git_1.7.1-1_i386.deb > /dev/null 2>&1
if [ $? -gt 0 ]; then
apt-get -f --force-yes --yes install>/dev/null 2>&1
fi
dpkg -i git_1.7.1-1_i386.deb > /dev/null 2 > &1
# This is needed to complet Git installation
dpkg -i git-core_1.7.1-1_all.deb>/dev/null 2 > &1
Be Sociable, Share!
 
Does that help to solve your problem?
VN:F [1.8.5_1061]
Rating: +15 (from 23 votes)
19 votes 'YES'  4 votes 'NO'
TAGS
RELATED
Pages
Posts
SOCIAL
Be Sociable, Share!

7 Responses to “Automatically install dependencies with “dpkg -i””

  1. byounggwon says:

    when i have tried “apt-get -f –force-yes –yes install” after dependency error, apt-get removes the before deb pkg….

    would you help me …

  2. magor says:

    that happened to me just moments ago, its because the package you tried to install has unresolvable dependencies (understand: non-existent packages)

    • Well, in my case it was a part of script. I knew that Debian knows how to get all dependencies. “This snippet will only work if you Linux distro knows how to get all packages”.

      In the case that Linux doesn’t know how to get the dependency or what the dependency is apt-get -f –force-yes –yes install will not work.

      @byounggwon. What was you installing and on which linux distro?

    • byounggwon says:

      Magor, you are right.
      The package I tried has a wrong version of dependencies..
      I modified the version, and then all was install well…
      thank you…

      And,
      Neokrates, my linux is Ubuntu 10.04.1
      Thank you…

  3. Ayke van Laethem says:

    A much easier method is the ‘gdebi’ program. Gdebi is graphical, but gdebi-core is for the command line.
    sudo apt-get install gdebi-core
    sudo gdebi <package_name.deb>

    • Berlioz says:

      Gdebi does not seem to be established tool used by many distros. It also does not seem to be mature or scripting-oriented. If i want a script which will work with many distros and many versions, i would rather take something well known, stable, accepted and established. Both apt and dpkg are such choices, i think.

  4. […] I have come across this strategy to sort this out (from Thinkplexx): […]

Leave a Reply