案例1:update is not working
1、操作系统:
ubuntu 12.04 desktop
2、问题:
执行 apt-get update时,出现如下问题:
Hit http://archive.ubuntu.com precise Release.gpg
Hit http://archive.ubuntu.com precise-updates Release.gpg
Hit http://archive.ubuntu.com precise-backports Release.gpg
Hit http://archive.ubuntu.com precise-security Release.gpg
Hit http://ppa.launchpad.net precise Release.gpg
Hit http://archive.ubuntu.com precise Release
Hit http://ppa.launchpad.net precise Release
Hit http://archive.ubuntu.com precise-updates Release
Hit http://archive.ubuntu.com precise-backports Release
Hit http://ppa.launchpad.net precise/main Sources
Hit http://archive.ubuntu.com precise-security Release
Hit http://ppa.launchpad.net precise/main amd64 Packages
Hit http://ppa.launchpad.net precise/main i386 Packages
Ign http://ppa.launchpad.net precise/main TranslationIndex
Ign http://ppa.launchpad.net precise/main Translation-en
Hit http://archive.ubuntu.com precise/main Sources
Hit http://archive.ubuntu.com precise/restricted Sources
Hit http://archive.ubuntu.com precise/multiverse Sources
Hit http://archive.ubuntu.com precise/restricted amd64 Packages
Hit http://archive.ubuntu.com precise/multiverse amd64 Packages
Hit http://archive.ubuntu.com precise/main i386 Packages
Hit http://archive.ubuntu.com precise/restricted i386 Packages
Hit http://archive.ubuntu.com precise/multiverse i386 Packages
Hit http://archive.ubuntu.com precise/main TranslationIndex
Hit http://archive.ubuntu.com precise/multiverse TranslationIndex
Hit http://archive.ubuntu.com precise/restricted TranslationIndex
Hit http://archive.ubuntu.com precise/universe TranslationIndex
Hit http://archive.ubuntu.com precise-updates/restricted Sources
Hit http://archive.ubuntu.com precise-updates/universe Sources
Hit http://archive.ubuntu.com precise-updates/multiverse Sources
Hit http://archive.ubuntu.com precise-updates/main amd64 Packages
Hit http://archive.ubuntu.com precise-updates/restricted amd64 Packages
Hit http://archive.ubuntu.com precise-updates/universe amd64 Packages
Hit http://archive.ubuntu.com precise-updates/multiverse amd64 Packages
Hit http://archive.ubuntu.com precise-updates/restricted i386 Packages
Hit http://archive.ubuntu.com precise-updates/universe i386 Packages
Hit http://archive.ubuntu.com precise-updates/multiverse i386 Packages
Hit http://archive.ubuntu.com precise-updates/main TranslationIndex
Hit http://archive.ubuntu.com precise-updates/multiverse TranslationIndex
Hit http://archive.ubuntu.com precise-updates/restricted TranslationIndex
Hit http://archive.ubuntu.com precise-updates/universe TranslationIndex
Hit http://archive.ubuntu.com precise-backports/main Sources
Hit http://archive.ubuntu.com precise-backports/restricted Sources
Hit http://archive.ubuntu.com precise-backports/universe Sources
Hit http://archive.ubuntu.com precise-backports/multiverse Sources
Hit http://archive.ubuntu.com precise-backports/main amd64 Packages
Hit http://archive.ubuntu.com precise-backports/restricted amd64 Packages
Hit http://archive.ubuntu.com precise-backports/universe amd64 Packages
Hit http://archive.ubuntu.com precise-backports/multiverse amd64 Packages
Hit http://archive.ubuntu.com precise-backports/main i386 Packages
Hit http://archive.ubuntu.com precise-backports/restricted i386 Packages
Hit http://archive.ubuntu.com precise-backports/universe i386 Packages
Hit http://archive.ubuntu.com precise-backports/multiverse i386 Packages
Hit http://archive.ubuntu.com precise-backports/main TranslationIndex
Hit http://archive.ubuntu.com precise-backports/multiverse TranslationIndex
Hit http://archive.ubuntu.com precise-backports/restricted TranslationIndex
Hit http://archive.ubuntu.com precise-backports/universe TranslationIndex
Hit http://archive.ubuntu.com precise-security/main Sources
Hit http://archive.ubuntu.com precise-security/restricted Sources
Hit http://archive.ubuntu.com precise-security/universe Sources
Hit http://archive.ubuntu.com precise-security/multiverse Sources
Hit http://archive.ubuntu.com precise-security/main amd64 Packages
Hit http://archive.ubuntu.com precise-security/restricted amd64 Packages
Hit http://archive.ubuntu.com precise-security/universe amd64 Packages
Hit http://archive.ubuntu.com precise-security/multiverse amd64 Packages
Hit http://archive.ubuntu.com precise-security/restricted i386 Packages
Hit http://archive.ubuntu.com precise-security/universe i386 Packages
Hit http://archive.ubuntu.com precise-security/multiverse i386 Packages
Hit http://archive.ubuntu.com precise-security/main TranslationIndex
Hit http://archive.ubuntu.com precise-security/multiverse TranslationIndex
Hit http://archive.ubuntu.com precise-security/restricted TranslationIndex
Hit http://archive.ubuntu.com precise-security/universe TranslationIndex
Get:1 http://archive.ubuntu.com precise/universe Sources [6239 kB]
Get:2 http://archive.ubuntu.com precise/main amd64 Packages [1640 kB]
Get:3 http://archive.ubuntu.com precise/universe amd64 Packages [6167 kB]
Get:4 http://archive.ubuntu.com precise/universe i386 Packages [6180 kB]
Get:5 http://archive.ubuntu.com precise/main Translation-en [726 kB]
Hit http://archive.ubuntu.com precise/multiverse Translation-en
100% [5 Translation-en bzip2 0 B] [Waiting for headers] 3422 kB/s 0s
bzip2: Data integrity error when decompressing.
Input file = (stdin), output file = (stdout)
It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.
You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.
Hit http://archive.ubuntu.com precise/restricted Translation-en
Get:6 http://archive.ubuntu.com precise-updates/main Sources [504 kB]
Get:7 http://archive.ubuntu.com precise-updates/main i386 Packages [888 kB]
Hit http://archive.ubuntu.com precise-updates/main Translation-en
Hit http://archive.ubuntu.com precise-updates/multiverse Translation-en
Hit http://archive.ubuntu.com precise-updates/restricted Translation-en
Hit http://archive.ubuntu.com precise-updates/universe Translation-en
Hit http://archive.ubuntu.com precise-backports/main Translation-en
Hit http://archive.ubuntu.com precise-backports/multiverse Translation-en
Hit http://archive.ubuntu.com precise-backports/restricted Translation-en
Hit http://archive.ubuntu.com precise-backports/universe Translation-en
Get:8 http://archive.ubuntu.com precise-security/main i386 Packages [406 kB]
Hit http://archive.ubuntu.com precise-security/main Translation-en
Hit http://archive.ubuntu.com precise-security/multiverse Translation-en
Hit http://archive.ubuntu.com precise-security/restricted Translation-en
Hit http://archive.ubuntu.com precise-security/universe Translation-en
Get:9 http://archive.ubuntu.com precise/universe Translation-en [4133 kB]
Fetched 726 kB in 25s (29.0 kB/s)
W: Failed to fetch gzip:/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise_universe_source_Sources Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise_main_binary-amd64_Packages Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise_universe_binary-amd64_Packages Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise_universe_binary-i386_Packages Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise-updates_main_source_Sources Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise-updates_main_binary-i386_Packages Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise-security_main_binary-i386_Packages Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_precise_universe_i18n_Translation-en Encountered a section with no Package: header
E: Some index files failed to download. They have been ignored, or old ones used instead.
3、问题分析
apt-get的缓存错误。
4、解决方案
sudo apt-get clean
cd /var/lib/apt/lists/partial
sudo rm *
sudo apt-get clean
sudo apt-get update && sudo apt-get upgrade
或者换一个代理服务器。
参考网址:http://askubuntu.com/questions/340658/apt-get-update-is-not-working
案例2:How do I resolve unmet dependencies?
1、操作系统:
ubuntu 12.04 desktop
2、问题:
执行 apt-get update时,出现如下问题:
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:
package1 : Depends: package2 (>= 1.8) but 1.7.5-1ubuntu1 is to be installed
E: Unable to correct problems, you have held broken packages.
3、问题分析
问题原因:
1.Computer is not connected to the Internet
2.The repository containing the depandancy package is not enabled
3.Package catalog is not updated
4.The version of the depandancy in the current repository is old
5.Software index is broken
6.The depandancy is not available for ubuntu
4、问题解决
It is always a good idea to back up configuration files like /etc/apt/sources.list
, so you can revert the changes if needed.
-
If the
error
shows something like this:<some-package>: Depends: <other-package> (= version) but this-version is to be installed
Then make sure that the
restricted
anduniverse
repositories are enabled. Hit Alt+F2, typesoftware-properties-gtk
and hit Enter.Under
Ubuntu Software
tab, enable all the repositories. -
One possible cause of unmet dependencies could be corrupted package database, and/or some packages weren’t installed properly. To fix this problem, hit Alt+Ctrl+T to open terminal and try to run one of the following commands:
sudo apt-get clean
or,
sudo apt-get autoclean
apt-get clean
clears out the local repository of retrieved package files (the .deb files). It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/.apt-get autoclean
clears out the local repository of retrieved package files, but unlikeapt-get clean
, it only removes package files that can no longer be downloaded, and are largely useless. -
One of the most basic fixes to resolve dependencies problems is to run:
sudo apt-get -f install
The
-f
hare stands for “fix broken”.Apt
will attempt to correct broken dependencies. If you manually installed a package that had unmet dependencies,apt-get
will install those dependencies, if possible, otherwise it may simply remove the package that you installed in order to resolve the problem.Then run:
sudo dpkg --configure -a
Then run this again:
sudo apt-get -f install
If the output is:
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
That means it failed.
-
Next solution is to run:
sudo apt-get -u dist-upgrade
If it shows any held packages, it is best to eliminate them. Packages are held because of dependency conflicts that
apt
cannot resolve. Try this command to find and repair the conflicts:sudo apt-get -o Debug::pkgProblemResolver=yes dist-upgrade
If it cannot fix the conflicts, it will exit with:
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
Delete the held packages one by one, running
dist-upgrade
each time, until there are no more held packages. Then reinstall any needed packages. Be sure to use the--dry-run
option, so that you are fully informed of consequences:sudo apt-get remove --dry-run package-name
Since removing the package you are trying to install may not be ideal, you might also try finding a repository that has the packages you need to satisfy the dependencies.
Finally, if all else fails, you can attempt to satisfy the dependencies yourself, either by finding and installing the necessary packages, or by installing them from source and then creating “deb” packages for them.
Disable/Remove/Purge PPAs:
PPAs (Personal Package Archive) are repositories hosted on Launchpad. You can use PPAs to install or upgrade packages that are not available in the official Ubuntu repositories.
One of the most common causes of unmet dependencies are PPAs, specially when used to upgrade the existing package in Ubuntu repositories. To solve the problem you have tree options, disable, purge (revert back to original package in Ubuntu repositories) or remove PPA.
-
Disable:
Disabling a PPA means no more updates for the packages installed from that PPA. To disable a PPA: Open
Software Center > Edit > Software Sources
Or,Hit Alt+F2 and run
software-properties-gtk
.Click on
Other Software
tab, you'll see that each PPA have two lines here, one for the compiled packages and one for the source,Uncheck
both lines to disable a PPA. Hare you can also add and remove PPAs. -
Purge:
Purging a PPA means, downgrading the packages in the selected PPA to the version in the official Ubuntu repositories and disabling that PPA. PPA Purge does exactly that. To install PPA Purge run the following command:
sudo apt-get install ppa-purge
But, Considering the question apt
is broken so the above command will fail. So use this command
mkdir ppa-purge && cd ppa-purge && wget http://mirror.pnl.gov/ubuntu/pool/universe/p/ppa-purge/ppa-purge_0.2.8+bzr56_all.deb && wget http://mirror.pnl.gov/ubuntu//pool/main/a/aptitude/aptitude_0.6.6-1ubuntu1_i386.deb && sudo dpkg -i ./*.deb
To use PPA Purge:
sudo ppa-purge ppa:someppa/ppa
If 'ppa-purge' command fails for some reason, you can't run 'ppa-purge' again unless you re-enable the PPA (To enable the PPA follow the same steps as disabling a PPA and Check
the both lines of a particular PPA to enable it).
Note: PPA Purge
doesn't remove PPAs (may be in future), So you'll have to manually remove the PPA.
-
Remove:
If the package installed from a PPA doesn't exist in official Ubuntu repositories then using
PPA Purge
is not recommended, because there's nothing to be downgraded andPPA Purge
wouldn't delete it either. To remove a PPA and installed packages run the following commands: (Ignore the first command if you don't want to remove the installed packages)sudo apt-get autoremove --purge package-name sudo add-apt-repository --remove ppa:someppa/ppa sudo apt-get autoclean
Alternatively you can use Y PPA Manager
to disable/remove/purge PPA's (Details at the end of answer).
Preventive Measures:
So how can we avoid this from happening in the first place?
-
Keep Ubuntu Up to date. Ubuntu automatically notifies when updates are available, you can also check for available updates by clicking on
Session Indicator
in Unity panel:Or, Hit Alt+Ctrl+T to open terminal and run following commands:
sudo apt-get update sudo apt-get upgrade
Update: Synchronizes your list of available packages with the servers in source repositories. Upgrade: Downloads & installs any newer versions of your installed packages.
- If you decide to add other repositories to sources.list, make sure that the repository is meant to work (and known to work) with Ubuntu. Repositories that are not designed to work with your version of Ubuntu can introduce inconsistencies in your system and might force you to re-install. Also, make sure that you really need to add external repositories as the software package(s) you are looking for may already have been introduced into the official repositories! Source
-
Remove duplicate PPAs.
Y PPA Manager
(installation guide at the end of answer) can easily scan and remove duplicate PPAs.- Hit Alt+F2 and run
y-ppa-manager
to open Y PPA Manager. - Once open, double click or hit Enter on
Advanced
. - In resulting window select
Scan and remove duplicate PPAs
and click OK.
- Hit Alt+F2 and run
Getting Help:
When asking for help on Askubuntu or any other help forum, you should include the output of the following commands in your question:
-
sudo apt-get install package-name
Output of actual error. -
cat /etc/apt/sources.list
This will show your sources.list -
cat /etc/apt/sources.list.d/*
This will show the list of PPAs (If any).
Additional Sources:
- 'apt' Ubuntu Manpage
- 'apt-get' Ubuntu Manpage
- 'apt-get/how-to' Community Ubuntu documentation
- 'Repositories/Ubuntu' Community Ubuntu documentation
- 'Repositories/CommandLine' Community Ubuntu documentation