出于好奇,我想知道为什么 debian 或 ubuntu 用户在安装新软件之前大多数时候都必须运行sudo apt-get update
或sudo yum update
(对于其他发行版而言)。例如:
sudo apt-get update
sudo apt-get install -y mongodb-org
答案1
这在某种程度上是这样的:
Look before you leap
并且可以说成update before install
。
现在请注意,在 Linux 世界中update
和upgrade
是两个不同的术语。要获得简短而有趣的知识,请参阅以下帖子询问Ubuntu,Unix StackEx和它是自由/开源软件。
现在可以通过以下方法找出两者之间的差异apt-get 命令:
update
Used to re-synchronize the package index files from their sources.
The indexes of available packages are fetched from the location(s)
specified in /etc/apt/sources.list(5).
An update should always be performed before an upgrade or dist-upgrade.
upgrade
Used to install the newest versions of all packages currently installed on the
system from the sources enumerated in /etc/apt/sources.list(5).
Packages currently installed with new versions available are retrieved and
upgraded; under no circumstances are currently installed packages removed,
nor are packages that are not already installed retrieved and installed.
New versions of currently installed packages that cannot be upgraded without
changing the install status of another package will be left at their current
version.
An update must be performed first so that apt-get knows that new versions
of packages are available.
我建议您再次阅读这两个命令的最后几行,它们明确回答了您的问题
You get the latest version of a package to install
另外,请参见下面的图片(由我创建)以获得更好的视图。
请随意添加更多详细信息。
答案2
sudo apt-get update
更新计算机已知的应用程序列表。如果您有一段时间没有运行此命令并尝试安装新软件,它将无法安装,因为您的计算机不知道它的存在。
答案3
如果您之前运行该命令的时间足够短,则不一定。
它只是更新存储库元数据,以确保后续命令不会因元数据过时而失败。