Automatically answer 'Yes' when using apt-get install

382

62

Is there a way to make apt-get install answer "yes" to the "Do you want to continue [y/N]?"?

Mistiry

Posted 2010-07-16T20:34:00.610

Reputation: 4 759

Answers

471

via the apt-get man page:

apt-get -y install [packagename]

jrc03c

Posted 2010-07-16T20:34:00.610

Reputation: 7 626

Is this the same as @bclermont answer (--yes --force-yes)? – jjxtra – 2018-07-05T19:16:55.007

182

The problem with:

apt-get --yes install $something

is that it will ask for a manual confirmation if the package signature owner's public-key is not in the keyring, or some other conditions. to be sure it does not ask a confirmation just do this:

apt-get --yes --force-yes install $something

If you want to have these settings permanent, create a file in /etc/apt/apt.conf.d/, like /etc/apt/apt.conf.d/90forceyes with the following content:

APT::Get::Assume-Yes "true";
APT::Get::force-yes "true";

bclermont

Posted 2010-07-16T20:34:00.610

Reputation: 2 001

1Will this work when it says "To continue type in the phrase 'Yes, do as I say!'" too? If not what is the work-around then? I encounter this when trying to replace sysvinit with systemd in my chrooted debian image. – Lennart Rolland – 2015-05-29T19:38:18.627

14

Please don't ever use --force-yes: as this reply to a related thread on debian-devel suggests, --force-yes might render the system unusable. (I'm not downvoting because the answer actually addresses the problem as stated by the OP, but I'd add a BIG RED WARNING to the answer anyway.)

– kostix – 2015-06-10T14:16:08.573

7APT::Get::Assume-Yes "true"; helped me to avoid interrupt in an installation in a docker container. – Mehdi Sadeghi – 2016-02-22T11:18:14.957

4+1 for variety. All the -y were getting boring. (Plus it's a more complete answer.) – Paused until further notice. – 2010-07-16T23:30:21.627

5

force-yes has been deprecated. https://tracker.mender.io/browse/CFE-2360

– rrawat – 2017-09-27T22:23:24.187

+1 the best answer - I was looking for the solution to force yes, rather than having to specify it each time – Robin Winslow – 2012-10-11T12:15:02.850

53

Note that if you also want to automatically go by the default answers when an interactive prompt appears, you can use DEBIAN_FRONTEND=noninteractive

Single install:

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install [packagename]

E.g.:

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install postfix

All updates:

sudo DEBIAN_FRONTEND=noninteractive apt-get -y update 

You can set up finer options with -o Dpkg::Options::="--force-confdef" and -o Dpkg::Options::="--force-confold".

Examples:

apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"

or

apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

Example of interactive prompt:

enter image description here

Interesting read: Perform an unattended installation of a Debian package

Franck Dernoncourt

Posted 2010-07-16T20:34:00.610

Reputation: 13 518

1Great answer. Even with -y, I still got prompts asking if I wanted to restart services. I needed this to completely eliminate all prompts. – wisbucky – 2019-06-19T22:01:08.463

14

APT::Get::Assume-Yes "true";

APT::Get::force-yes "true";

This should at least be in /etc/apt/apt.conf and commented out. I worry Ubuntu is taking the Microsoft tack of always asking for permission.

"Are you sure?", of course I am sure, I am not a trained monkey simply typing away at the keyboard, going click happy.

Next the door will ask, "Are you sure you want to go outside?"
The oven will ask, "Are you sure you want to cook?"
The automobile will ask, "Are you sure you want to apply brakes?"
The fire extinguisher will ask, "Are you sure you want to put out the fire?"
I am sorry Dave, I can't let you do that.
HAL9000 could use a contraction but Data could not, or couldn't.

Ajax4Hire

Posted 2010-07-16T20:34:00.610

Reputation: 157

3The difference with HAL9000 and dpkg asking for permission is that HAL said "no, period", whereas the "Yes, do as I say" thing only shows up if you're about to completely and utterly break your system. If that's what you want, sure, go ahead. But having a warning in that case seems reasonable. – Wouter Verhelst – 2015-06-11T13:41:51.210

9

From the apt-get HOWTO

Use the -y switch: apt-get -y install packagename

Powerlord

Posted 2010-07-16T20:34:00.610

Reputation: 814

7

apt-get -y update
apt-get -y install [package]

steve.lippert

Posted 2010-07-16T20:34:00.610

Reputation: 1 970

@amyassin the apt-get update command requires root permissions because it updates the local package lists (indexes), which are system files owned by root. – jjmontes – 2015-10-09T11:31:39.697

@amyassin update and upgrade ask for permission because they are downloading stuff to the machine - thus taking up bandwidth and disk space. Believe it or not, back in the day, those were valuable commodities. – Chiwda – 2019-11-23T03:15:57.620

2@Chiwda I live in a third world country where those things are still valuable commodities :) – amyassin – 2020-01-01T13:05:20.187

2+1 , but why update needs permission? – amyassin – 2012-05-22T20:31:41.073

4

generally the options from the manual should work well

apt-get -y --force-yes install package

if it does not succeed you can try to use the yes command.

yes | apt-get -y --force-yes install package

did use this with my vagrant shell provisioning script

PS: in case you want non-interactive but with generally stating no then you can try this:

yes no | apt-get install package

Summer-Sky

Posted 2010-07-16T20:34:00.610

Reputation: 161

1

The new (well) apt alias takes the -y (--yes) switch too:

sudo apt -y upgrade

yPhil

Posted 2010-07-16T20:34:00.610

Reputation: 1 261

1

If you always want the -y argument I'd advise adding the line

alias apt-get='apt-get -y' #Automatic -y argument on apt-get commands

into your .bashrc. This, as the comment explains, will automatically add the -y argument to all your apt-get commands and therefore approves all the downloads.


NOTE: This will remain true until you revert your .bashrc and restart the shell.

Joseph Stevens

Posted 2010-07-16T20:34:00.610

Reputation: 11

1

I was looking for a way to select a non-default in a script, specifically when installing wireshark, and ended up using tmux to interact with a shell, as follows:

# Start a detached root session
sudo tmux new-session -d
# Send the command
sudo tmux send-keys "DEBIAN_FRONTEND=readline apt-get -qq install wireshark-common; exit" enter
# Wait for the tmux session to get to the interactive stage
sleep 5
# Answer the question
sudo tmux send-keys "yes" enter
# Now attach to the session so we wait for command completion
sudo tmux attach

Stephen Ramm

Posted 2010-07-16T20:34:00.610

Reputation: 11

0

Using yes is package manager independent. E.g.

yes | apt-get install curl

whirlwin

Posted 2010-07-16T20:34:00.610

Reputation: 637