3

I am unable to install any package using command "apt-get install".

Whenever I execute above command to install any package, it shows me a common error saying E: Package <PackageName> has no installation candidate

I tried following packages to install but every time I faced the same error

Command

sudo apt-get install apache2

Error

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package apache2 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  libapache2-mpm-itk

E: Package 'apache2' has no installation candidate

Commmand

sudo apt-get install postfix nap ntpdate

Error

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package ntpdate is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package postfix is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'postfix' has no installation candidate
E: Package 'ntpdate' has no installation candidate

Also I tried to update and upgrade using following command

sudo apt-get update && sudo apt-get upgrade

But after that also; executing apt-get install command also shows the same error.

Please find my /etc/apt/sources.list file content as below, let me know if I made something wrong in configuration.

Please help me.

{Editor inserted copy of linked-to file:}

## deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi   
# Uncomment line below then 'apt-get update' to enable 'apt-get source'   
deb-src http://archive.raspbian.org/raspbian/ wheezy main contrib non-free rpi   


deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi   
deb http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi   
# Source repository to add   
deb-src http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi   
#deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi   
#deb http://archive.raspbian.org/raspbian jessie main contrib non-free rpi   
# Source repository to add   
#deb-src http://archive.raspbian.org/raspbian jessie main contrib non-free rpi
  • Are those r$s at the end of various lines in the pastebin actually in sources.list or just because you cut n' pasted it from some editor? It is simpler if you just use cat /etc/apt/sources.list. It is also simpler if you just paste the output into the question rather than use a pastebin link. – goldilocks Jun 16 '16 at 4:32
  • @goldilocks, yes its due to copy and pasting mistake. I have updated the link. – HarshIT Jun 26 '16 at 4:03
3

Looking at your sources.list file your problem may be that you are only using "Wheezy" {Debian/Raspian Version 7.x "OldStable"} sources but also have "jessie" {Debian/Raspian Version 8.x "Stable"} sources commented out - if you have previous had the latter uncommented you may have installed packages from the later version ones and then, when they were commented out again, you have versions installed that are later then the ones that are present in the older distribution.

You also have duplicate entries for the same source package repository:
deb-src http://archive.raspbian.org/raspbian/ wheezy main contrib non-free rpi

And very likely have two repositories for the SAME files:
deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi deb http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi

mirrordirector.raspbian.org is a special (virtual?) repository, it will redirect to a, hopefully, geographically good server for you/your RPi making the request and normally, I believe, it is all that you need to specify.

To resolve situations like this you may find that instead of apt-get you could try using aptitude in it's interactive mode - as it can help to explore your system's packages, it will show if you have multiple versions of packages available in your system, and it can allow you to choose which is installed manually - it keeps track of the interdependencies as you select and deselect them and will warn, if not prevent you, from putting together an incompatible set of inter-dependent packages.

  • Since this is tagged Jessie, I think you're right. My Raspbian is pretty vanilla, and my /etc/apt/sources.list only has one uncommented line: deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi – Hydraxan14 Apr 20 '17 at 15:18
  • The fact that apache2 of all things is not in the configured repositories is a giant red flag that the repository configuration is wrong. – Hydraxan14 Apr 20 '17 at 15:21
1

Fix for postfix, ntpdate

After searching the web for a while, I found the correct software. There is a program called gdebi that installs the packages with the dependencies, so that will be installed when you run the following script/s alongside (hopefully) nap, ntpdate, and postfix. These programs are made for Jessie systems, so you have to have the latest raspbian installed for them to work. If for some reason you have an old version, let me know and I can work around it :)

This is a temporary fix. I will have to dig deeper to find the real reason this is happening. I also notice that nap still seems to work? Try running 'sudo apt-get nap' and see if that works.

Run the following commands:

    sudo apt-get install gdebi
    cd ~/Downloads
    wget http://ftp.uk.debian.org/debian/pool/main/n/ntp/ntpdate_4.2.6.p5+dfsg-7+deb8u1_armhf.deb
    wget http://ftp.uk.debian.org/debian/pool/main/p/postfix/postfix_2.11.3-1_armhf.deb
    sudo gdebi ntpdate_4.2.6.p5+dfsg-7+deb8u1_armhf.deb
    sudo gdebi postfix_2.11.3-1_armhf.deb

I read through some of the comments and I noticed @goldilocks said to use armel, so if you get errors, try the following:

    sudo apt-get install gdebi
    cd ~/Downloads
    wget http://ftp.uk.debian.org/debian/pool/main/n/ntp/ntpdate_4.2.6.p5+dfsg-7+deb8u1_armel.deb
    wget http://ftp.uk.debian.org/debian/pool/main/p/postfix/postfix_2.11.3-1_armel.deb
    sudo gdebi ntpdate_4.2.6.p5+dfsg-7+deb8u1_armel.deb
    sudo gdebi postfix_2.11.3-1_armel.deb
0

This generally means the package exists, but it is not available from the Raspberry Pi application source.

Try running some of the following commands:

    sudo apt-get update
    sudo apt-get install build-essential
    sudo dpkg --configure -a
    sudo apt-get -f install

If you have no luck, I would reccomend searching on google for an ArmHF repository that contains those packages, and adding it using some instructions easily found online also.

Good luck!

  • Thanks. but above commands did not work. I also tried to search ArmHF but could not understand what should I do or how to use them. Kindly guide me (if possible). I am not familiar with linux system as I am an iOS Developer. – HarshIT Jun 26 '16 at 5:24
  • "armhf" is Debian's name for the ARMv7 architecture, which is usable on the Pi 2 or 3 (although those packages may or may not work within Raspbian). You can search for that stuff via here. If you aren't using a 2/3, or the package doesn't work/won't install, use armel, on which Raspbian is based. You'll see the various architectures listed on the second line of each search result hit next to the version number; all is synonymous with "any" otherwise there will be a list such as "amd64 arm64 armel armhf i386 ...". – goldilocks Jun 26 '16 at 16:05
0

Today I ran into this problem because the power supply I was trying to use failed half way through a package update. This resulted in a corrupted package file in /var/lib/apt/lists that was half downloaded. I ended up getting the same "Package has no installation candidate" error for any package I didn't already have installed. Usually in this case one would recommend just reinstalling, but since I had another raspbian distro installed that I could reference, I was able to compare the two /var/lib/apt/lists directories and see which file was half complete. In my case it was mirrordirector.raspbian.org_raspbian_dists_stretch_main_binary-armhf_Packages as it was only abound 2MB in size of the 60MB that is should be. I simply deleted that file and then ran apt-get update again.

I would only recommend this as a last resort as you could end up corrupting your system. For me, it saved me about an hour of time reinstalling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.