我想查看哪些软件包可以更新/升级,但实际上不更改任何文件,因为有些软件包我不想更新。那么是否可以在例外的情况下使用 apt-get update?
答案1
我使用apt list --upgradable
。
下一个替代方案是apt-get --simulate upgrade
。(基于@EightBitTony)
以下是不同选项的输出(希望对某些人有帮助):
me@machine:~$ apt list --upgradable
Listing... Done
kubernetes-cni/kubernetes-xenial 0.7.5-00 amd64 [upgradable from: 0.6.0-00]
N: There are 3 additional versions. Please use the '-a' switch to see them.
me@machine:~$ apt-get --simulate upgrade
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
kubernetes-cni
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Inst kubernetes-cni [0.6.0-00] (0.7.5-00 kubernetes-xenial:kubernetes-xenial [amd64])
Conf kubernetes-cni (0.7.5-00 kubernetes-xenial:kubernetes-xenial [amd64])
me@machine:~$ apt-get -u upgrade --assume-no
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
me@machine:~$ sudo apt-get -u upgrade --assume-no
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
kubernetes-cni
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 6,473 kB of archives.
After this operation, 4,278 kB of additional disk space will be used.
Do you want to continue? [Y/n] N
Abort.
me@machine:~$ sudo apt-get -u -V upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
kubernetes-cni (0.6.0-00 => 0.7.5-00)
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 6,473 kB of archives.
After this operation, 4,278 kB of additional disk space will be used.
Do you want to continue? [Y/n] n
Abort.
答案2
从 apt-get 手册页中,
-s, --simulate, --just-print, --dry-run, --recon, --no-act No action; perform a simulation of events that would occur but do not actually change the system. Configuration Item: APT::Get::Simulate. Simulation run as user will deactivate locking (Debug::NoLocking) automatic. Also a notice will be displayed indicating that this is only a simulation, if the option APT::Get::Show-User-Simulation-Note is set (Default: true). Neither NoLocking nor the notice will be triggered if run as root (root should know what he is doing without further warnings by apt-get). Simulate prints out a series of lines each one representing a dpkg operation, Configure (Conf), Remove (Remv), Unpack (Inst). Square brackets indicate broken packages and empty set of square brackets meaning breaks that are of no consequence (rare).
所以只要确保你apt-get -s upgrade
。
如果您想升级某些软件包,只需执行此操作,apt-get install <package name>
它就会更新已安装的软件包。但是,它还必须更新所有依赖项,并且根据依赖项的不同,这可能会级联成大量更新。
如果我落后于软件包更新,我会对apt-get install
一些较大的软件包(可能是 php、apache2 等)进行更新,这样我就可以控制它们并检查任何问题,然后apt-get upgrade
在我完成后。
答案3
列出需要升级的软件包及其版本:
$ sudo apt-get -u -V upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
mysql-client-5.5 (5.5.29-0ubuntu0.12.04.2 => 5.5.32-0ubuntu0.12.04.1)
mysql-server-5.5 (5.5.29-0ubuntu0.12.04.2 => 5.5.32-0ubuntu0.12.04.1)
mysql-server-core-5.5 (5.5.29-0ubuntu0.12.04.2 => 5.5.32-0ubuntu0.12.04.1)
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
然后你可以选择升级内容:
$ sudo apt-get --only-upgrade install mysql-client-5.5
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
firefox-globalmenu
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
libterm-readkey-perl
The following NEW packages will be installed:
libterm-readkey-perl
The following packages will be upgraded:
mysql-client-5.5
1 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 8,123 kB of archives.
After this operation, 139 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main libterm-readkey-perl i386 2.30-4build3 [28.4 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main mysql-client-5.5 i386 5.5.32-0ubuntu0.12.04.1 [8,094 kB]
...
如果有任何旧的依赖项被删除,则可以运行apt-get autoremove
,如您所见,将提示安装任何新的依赖项。该--only-upgrade
标志不是必需的,但如果您想确保不会意外安装新软件包而不是升级现有软件包,则该标志很有用,即您遇到以下情况之一并意外输入了错误的软件包:
$ sudo apt-get --only-upgrade install mysql-proxy
Reading package lists... Done
Building dependency tree
Reading state information... Done
Skipping mysql-proxy, it is not installed and only upgrades are requested.
The following package was automatically installed and is no longer required:
firefox-globalmenu
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
答案4
apt-get -s upgrade
仅进行模拟的问题对您有帮助吗?然后您可以使用更新每个想要的包apt-get install <thepackage>
。
如果您希望与良好的 CLI GUI 进行交互,请使用aptitude
。如果尚未安装,请使用 安装apt-get install aptitude
。