How to install a package with apt without the "Do you want to continue [Y/n]?" prompt?
sudo apt-get install -y whatever
From the man page (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.
For apt-get, -y
or --assume-yes
work well (as @rinzwind explained) and I assume that's the best answer here. For many such interactive administrative operations, there is a similar command.
Another pretty generic way to do this is something like :
$ echo "y" | sudo apt-get install edamame_biscuit
(Where edamame-biscuit is the (made-up) package you want to install, and "y" is assumed to be a legitimate response ; substitute with "yes" or other text as needed.)
A 'feature' of this method is that this will break if you are incorrectly assuming only one interactive prompt. If there are some more potentially unwanted prompts you might not want to say yes to, you avoid the situation of having the system roll along without asking.
First of all, lets understand why the message appears.
If the package does not have dependencies that you have not installed, apt never asks you:
➜ ~ 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) ...
Whereas if you want to install a package that depends on packages you didn't mention it asks:
➜ ~ 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]
It doesn't ask if you list the dependencies explicitly:
➜ ~ 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])
But, then, how to make it that it doesn't ask you at all? Through Rizwind's answer covers ad-hoc and scripting solutions (in fact, that option is more used in scripts) you could instead modify your apt.conf
file and add:
APT::Get::Assume-Yes
Something like this should be enough:
echo 'APT::Get::Assume-Yes;' | sudo tee -a /etc/apt/apt.conf.d/00Do-not-ask
Note, this won't allow other more egregious prompts that you should verify, like:
➜ ~ sudo apt-get install sonar
WARNING: The following packages cannot be authenticated!
sonar
Install these packages without verification? [y/N]
Which is why I wouldn't recommend the use of yes | ...
, since this warning would be ignored.
Add -y
to any library install
Eg : sudo apt-get install -y nodejs
Eg : sudo apt-get install -y postgres
Eg : sudo apt-get install -y mongodb
There is --force-yes as well
, and careful of accidental spaces.
depreciated for recent distros