当前位置: 首页>>技术教程>>正文


如何在没有“你想继续[是/否]?”提示的情况下安装apt软件包?

, ,

问题描述

当然,当你输入:

sudo apt-get install whatever

它问你:

Do you want to continue [Y/n]? 

有没有什么方法可以安装它而不会问我是否要继续?我真的不在乎太空,我已经足够了。

最佳解决办法

sudo apt-get install -y whatever

从手册页(man apt-get):

 -y, --yes, --assume-yes

           Automatic yes to prompts; assume "yes" as answer to all prompts and
           run non-interactively. If an undesirable situation, such as
           changing a held package, trying to install a unauthenticated
           package or removing an essential package occurs then apt-get will
           abort. Configuration Item: APT::Get::Assume-Yes.

次佳解决办法

对于apt-get,-y--assume-yes效果很好(正如@rinzwind所解释的那样),我认为这是最好的答案。对于许多这样的交互式管理操作,存在类似的命令。

另一种非常通用的方法是这样的:

 $ echo "y" | sudo apt-get install edamame_biscuit

(其中edamame-biscuit是您要安装的(made-up)程序包,并且假定”y”是合法响应;根据需要用”yes”或其他文本替换。)

这种方法的’feature’如果您错误地假设只有一个交互式提示,则会中断。如果还有一些可能不需要的提示,您可能不想说“是”,则可以避免让系统滚动而不询问的情况。

第三种解决办法

首先,让我们理解消息出现的原因。事实上,如果软件包没有你尚未安装的依赖项,或者你明确告诉它要安装,那么apt永远不会要求你:

➜  ~  sudo apt-get -qq install xfce4-screenshooter
Selecting previously unselected package xfce4-screenshooter.
(Reading database ... 296146 files and directories currently installed.)
Preparing to unpack .../xfce4-screenshooter_1.8.1-2_amd64.deb ...
Unpacking xfce4-screenshooter (1.8.1-2) ...
Processing triggers for hicolor-icon-theme (0.13-1) ...
Processing triggers for man-db (2.6.7.1-1) ...
Processing triggers for gnome-menus (3.13.3-1) ...
Processing triggers for desktop-file-utils (0.22-1) ...
Processing triggers for mime-support (3.56) ...
Setting up xfce4-screenshooter (1.8.1-2) ...

虽然如果你想安装一个依赖于你没有提到的包的包,它会问:

➜  ~  sudo apt-get -q install avis
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  libjzlib-java libmina-java libslf4j-java
Suggested packages:
  libmina-java-doc libspring-beans-java libcommons-logging-java
  liblog4j1.2-java
The following NEW packages will be installed:
  avis libjzlib-java libmina-java libslf4j-java
0 upgraded, 4 newly installed, 0 to remove and 14 not upgraded.
Need to get 720 kB of archives.
After this operation, 1,258 kB of additional disk space will be used.
Do you want to continue? [Y/n] 

即使这样,也不会问你是否也隐含地说你要安装这些包:

➜  ~  apt-get -q install avis libjzlib-java libmina-java libslf4j-java
Reading package lists...
Building dependency tree...
Reading state information...
Suggested packages:
  libmina-java-doc libspring-beans-java libcommons-logging-java
  liblog4j1.2-java
The following NEW packages will be installed:
  avis libjzlib-java libmina-java libslf4j-java
0 upgraded, 4 newly installed, 0 to remove and 14 not upgraded.
Inst libjzlib-java (1.1.3-1 Debian:testing [all])
Inst libslf4j-java (1.7.7-1 Debian:testing [all])
Inst libmina-java (1.1.7.dfsg-11 Debian:testing [all])
Inst avis (1.2.2-2 Debian:testing [all])
Conf libjzlib-java (1.1.3-1 Debian:testing [all])
Conf libslf4j-java (1.7.7-1 Debian:testing [all])
Conf libmina-java (1.1.7.dfsg-11 Debian:testing [all])
Conf avis (1.2.2-2 Debian:testing [all])

但是,那么,如何确保它不会明确地问你?通过Rizwind回答应该涵盖ad-hoc和脚本解决方案(事实上,该选项更多用于脚本)您可以改为修改您的apt.conf文件并添加:

APT::Get::Assume-Yes

这样的事情应该足够了:

echo 'APT::Get::Assume-Yes;' | sudo tee -a /etc/apt/apt.conf.d/00Do-not-ask

请注意,这不允许您应该验证的其他更令人震惊的提示,例如:

➜  ~  sudo apt-get install sonar
WARNING: The following packages cannot be authenticated!
  sonar
Install these packages without verification? [y/N] 

这就是为什么我不建议使用yes | ...,因为这个警告会被忽略。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/1881.html,未经允许,请勿转载。