Is there a way to force "Yes" to any prompts when installing from apt-get (from a bash script)?
Solution 1
From the OPTIONS
section of 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.
Solution 2
There is a unix command called
yes
Without options it outputs the string "y" repeatedly until killed.
To use it, simply pipe the result to the command where you need the confirmations:
yes | apt-get install ...
Read more in the Unix man pages or in the SO post The “yes” command.
Solution 3
You can add -y
To any library install to answer yes
Eg : apt-get install -y nodejs
Eg : apt-get install -y gnupg
Related videos on Youtube
Startec
Updated on September 18, 2022Comments
-
Startec over 1 year
I am trying to make a
bash
script that automates the installation of several packages that I use on anyubuntu
machine. I frequently create virtual machines either through Amazon AWS or Digital Ocean and would like to just run one script to install all the packages I use.Some of the packages I would like to install are Emacs and Node.js
The normal way I install these would be to run
apt-get install Emacs
, and while doing this I am always prompted with a warning about how much space this app will take up and if I am sure I want to continue.Is there a way to automate this process, from a script, and always say "yes" to these prompts?
-
Joshua almost 8 yearsyes | apt-get ...
-
ToVine almost 8 yearsYou could also set up an image of a machine after you've set it up the way you want, and then make clones of it when you need new ones. Another option (especially if you have a long list that sometimes changes) is
pkgsync
. That program takes care of keeping the packages you need installed and up to date, and removing the ones that are not needed or actively unwanted. -
Jon Bentley almost 8 yearsYou might want to take a look at Ansible, Puppet, or Chef, which were designed to solve exactly this sort of problem. Ansible in particular is an easy one to get up and running as it operates over SSH. You can either send your own commands to your nodes, or (more likely) use the many modules that have been written to solve common tasks (such as installing packages). Once you have it set up, you only need to run a single command and it ensures that your entire inventory of servers are all in the correct state.
-
David Refoua about 7 yearsAlso read: superuser.com/a/164580/320611
-
-
Xen2050 almost 8 yearsI once ran into a package that was immune to
--yes
. APT didn't ask any questions, but I think a preinst or postinst script was always waiting for some trivial input -
Roger Lipscombe almost 8 years
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install foo
-
Startec almost 8 years@RogerLipscombe I am sorry, can you explain your comment a bit more?
-
Roger Lipscombe almost 8 yearsThe
DEBIAN_FRONTEND=noninteractive
stops preinst and postinst scripts from asking questions. -
David Marciel about 4 yearsthank you, I needed this command