111

Of course when you type:

sudo apt-get install whatever

It asks you:

Do you want to continue [Y/n]? 

Is there any way I can just install it without it asking me if I want to continue? I don't really care about space, I have more then enough.

Braiam
  • 67,791
  • 32
  • 179
  • 269
programking
  • 1,471

4 Answers4

156
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.
Pandya
  • 35,771
  • 44
  • 128
  • 188
Rinzwind
  • 299,756
19

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.

belacqua
  • 23,120
  • 16
    Also, yes | sudo apt-get install edamame-biscuit. Yes is a command that spams the word "yes" to its output. You can also make it output any other text as needed, see manpage. – Kroltan Sep 14 '14 at 19:59
  • 15
    @Kroltan The yes command (by default) just outputs the letter y followed by a newline as many times as is needed to fill the pipe buffer. To actually print the word yes, you have to use the command yes yes. – Jonathan Callen Sep 14 '14 at 20:03
  • 3
    yes, pardon my mistake – Kroltan Sep 14 '14 at 21:22
  • btw, edamame_biscuit is an invalid package name... just FYI. – Braiam Sep 15 '14 at 01:47
  • 4
    @Braiam I think that was the point, so it doesn't do anything if someone just pastes this in his/her shell. – Kroltan Sep 15 '14 at 02:10
  • Another FYI, if you try something like yes | sudo apt-get remove libc6 it won't remove the package. – Braiam Sep 15 '14 at 13:52
  • 2
    I particularly like the part "A 'feature' of this method is that this will break if you are incorrectly assuming only one interactive prompt." as spamming yes to everything can be extra dangerous. – BeowulfNode42 Sep 16 '14 at 07:21
  • I love it, so 'unix' :) – Gooshan Dec 20 '16 at 20:45
5

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.

Braiam
  • 67,791
  • 32
  • 179
  • 269
  • For "WARNING: The following packages cannot be authenticated!", what should one do about it? I get this for a Docker image (python:3.6-slim). Should I ask a separate question for that? – Martin Thoma Nov 05 '18 at 11:26
  • @MartinThoma usually, that's a problem with non-updated package list. Run apt-get update before installing. If that doesn't remove the message, ask a question with as much details you can, up to how you created the docker image. – Braiam Nov 05 '18 at 11:47
1

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

vijay
  • 121
  • 5