65

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.

97
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.
  • 9
    (how to live dangerously file) – user2413 Sep 14 '14 at 20:00
  • Thank you very much! I really should use that man page more often. :) – Luke Shimkus Sep 15 '14 at 19:52
  • 2
    That is why they are there @KingShimkus ;) – Rinzwind Sep 15 '14 at 19:52
  • 5
    sudo apt-get install -yeah whatever... – BoJack Horseman Sep 16 '14 at 9:14
  • Now if only this worked for upgrading the Docker package >.< If you have never upgraded Docker before, here's an image of what pops-up in the terminal even when you use --yes: Imgur It is exceptionally annoying since that forces interaction during the package update. – Spencer D Feb 23 '19 at 19:51
15

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.

  • 13
    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
  • 14
    @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
  • 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 2:10
  • 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 7:21
5

First of all, lets understand why the message appears. In fact, if the package do not have dependencies that you have not installed already or that you explicitly told it to install, 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) ...

While if you want to install a package that depends on packages you didn't mention it would ask:

➜  ~  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] 

Which even so, wouldn't ask if you also implicitly says that you want to install those package:

➜  ~  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 definitively? Through Rizwind answer should cover 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.

  • 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 5 '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 5 '18 at 11:47
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.