188

I am using Ubuntu 13.04 which I installed few days back. I am trying to install nodejs and npm. I tried to install from command line first and then uninstalled it. Then something broke.

sudo apt-get install -f nodejs npm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 nodejs : Conflicts: npm
E: Unable to correct problems, you have held broken packages.

The output of /etc/apt/sources.list is below:

# deb cdrom:[Ubuntu 13.04 _Raring Ringtail_ - Release amd64 (20130424)]/ raring main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://in.archive.ubuntu.com/ubuntu/ raring main restricted
deb-src http://in.archive.ubuntu.com/ubuntu/ raring main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://in.archive.ubuntu.com/ubuntu/ raring-updates main restricted
deb-src http://in.archive.ubuntu.com/ubuntu/ raring-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://in.archive.ubuntu.com/ubuntu/ raring universe
deb-src http://in.archive.ubuntu.com/ubuntu/ raring universe
deb http://in.archive.ubuntu.com/ubuntu/ raring-updates universe
deb-src http://in.archive.ubuntu.com/ubuntu/ raring-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://in.archive.ubuntu.com/ubuntu/ raring multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ raring multiverse
deb http://in.archive.ubuntu.com/ubuntu/ raring-updates multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ raring-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://in.archive.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse
deb-src http://in.archive.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu raring-security main restricted
deb-src http://security.ubuntu.com/ubuntu raring-security main restricted
deb http://security.ubuntu.com/ubuntu raring-security universe
deb-src http://security.ubuntu.com/ubuntu raring-security universe
deb http://security.ubuntu.com/ubuntu raring-security multiverse
deb-src http://security.ubuntu.com/ubuntu raring-security multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu raring partner
# deb-src http://archive.canonical.com/ubuntu raring partner

## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu raring main
deb-src http://extras.ubuntu.com/ubuntu raring main

The output of /etc/apt/sources.list.d/* is below:

deb http://ppa.launchpad.net/chris-lea/node.js/ubuntu raring main
# deb-src http://ppa.launchpad.net/chris-lea/node.js/ubuntu raring main
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
deb http://dl.google.com/linux/chrome/deb/ stable main
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
deb http://dl.google.com/linux/chrome/deb/ stable main
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
deb http://dl.google.com/linux/chrome/deb/ stable main
deb http://deb.opera.com/opera/ stable non-free
deb http://deb.opera.com/opera/ stable non-free
deb http://deb.opera.com/opera/ stable non-free
deb http://deb.opera.com/opera/ stable non-free
fosslinux
  • 3,831
John Qualis
  • 1,983

4 Answers4

363

Use aptitude instead of apt-get. It is more intelligent. It not only will handle downgrading conflicting packages for you, but will make a series of recommendations asking you which of many possible suggested working scenarios you would like.

sudo aptitude install myNewPackage

If you don't have aptitude on your machine yet, get it with

sudo apt-get install aptitude
DragonLord
  • 4,063
  • 2
  • 14
  • 11
  • 48
    The best answer. I have tried apt-get for the last couple of days. With aptitude this was solved in seconds :-) – Johan Karlsson Sep 04 '14 at 10:58
  • 8
    Thank you. I have spent so much time reading different ways to fix the problem that apt-get won't explain that I was astounded when aptitude just laid out the specific problem and even provided a solution. – bmacnaughton Apr 29 '15 at 00:54
  • Not to mention, it works on a headless server – bsd Jan 09 '16 at 12:04
  • yes, but why we need to use this solution? because almost computers are 64 bits now ?? – vanduc1102 Feb 03 '16 at 15:46
  • 8
    The one downside to this solution: you can't do sudo apt-get install aptitude if your packages are broken in the first place. – user13161 Mar 15 '17 at 20:08
  • This still applies on 14.04 – WillC May 19 '17 at 05:28
  • For more details on aptitude see this answer here too: https://askubuntu.com/a/223267/327339 – Gabriel Staples Dec 13 '17 at 03:42
  • 1
    Thanks a bunch!! Worked for me! Was able to get out of being held (apt-get) for over two days. aptitude is really smart!

    [Ubuntu MATE 18.04.1 LTS, Kernel Linux 4.15.0-45-generic x86_64, MATE 1.20.1]

    – ADEBISI Foluso A. Feb 05 '19 at 15:23
  • 2
    Wow! aptitude is so great! It had several issues with my mysql install & luckily it resolved itself my removing bunch of bad dependencies. – uday Aug 08 '19 at 14:59
  • Good lord, this was magical... The following actions will resolve these dependencies: [offers solution] Accept this solution?, YES, please!!! – brasofilo Apr 16 '20 at 03:21
  • This is the only real deal and the best workable answer – A l w a y s S u n n y Dec 02 '20 at 16:36
  • 1
    I keep getting following message Need to get 0 B of archives. After unpacking 0 B will be used. – alper Dec 25 '20 at 01:22
  • I just got: The following actions will resolve these dependencies: [solution: keep myNewPackage not installed]. Is that a joke?! – User9123 Apr 02 '22 at 18:56
  • aptitude solved my issue. I needed to script the install of libmagickwand-dev on 16.04 but there were issues on one particular server. aptitude asked a series of questions in order to allow it to be fixed. This example answered no to the first question and Yes to the following two, which allowed it to run without prompting for input: echo -e "n\nY\nY\n" | aptitude install libmagickwand-dev – jbobbins Oct 11 '22 at 01:58
  • Didn't work for me, sadly. It offered a solution but that was to keep what was already installed, and didn't then install the things I was asking it to. I'll keep trying. – IpsRich Dec 15 '22 at 16:05
37

You should be able to see the list of held packages by:

apt-mark showhold 

and then un-hold them by

sudo apt-mark unhold <package name>

After that, you should be able to remove the conflicting package (it seems to be npm) and then reinstall all.

If this fail, you can try the aptitude way --- often it's able to disentangle dependency trees better.

In both cases, be careful when applying commands, and check carefully the list of packages that are marked for remove.

Rmano
  • 31,947
4

For me to solve this problem, I just had to install synaptic first using below commmand, and then everything works fine.

sudo apt-get install synaptic
Richard
  • 8,502
  • 11
  • 47
  • 72
1

I found out that dpkg -r allows me to remove packages one-by-one, without triggering a cascade of other behaviour.

I am not sure this is a good solution, but I went with it and everything seems fine.