Is there a way to make apt-get install
automatically choose "yes" upon the Do you want to continue [y/N]?
confirmation dialog?
12 Answers
via the apt-get man page:
apt-get -y install [packagename]
-
4
-y
is abbreviated--yes
is synonym to--assume-yes
, while--force-yes
is a different option. it is used to decide prompts with a potentially more severe impact, like downgrades or breaking dependencies. refer to the man page (which is linked in the answer), it is all explained in detail there.– dlatikayAug 7, 2020 at 8:56 -
I'm still getting a prompt. I'd guess that apt is calling a post install cleanup step and that's hanging my script asking for confirmation to remove unused packages. I suppose I could disable that globally.– jorfusJul 14, 2022 at 23:10
To omit any confirmation request (including those regarding obligatory security checks and potentially dangerous system changes) use --force-yes
:
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";
The problem with plain --yes
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 impactful conditions.
-
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. May 29, 2015 at 19:38
-
21Please don't ever use
--force-yes
: as this reply to a related thread ondebian-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.)– kostixJun 10, 2015 at 14:16 -
6
-
After deprecation, use the new flags like
--allow-downgrades
,--allow-remove-essential
, or--allow-change-held-packages
. Jan 20 at 14:55
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:
Interesting read: Perform an unattended installation of a Debian package
-
1Great answer. Even with
-y
, I still got prompts asking if I wanted to restart services. I needed this to completely eliminate all prompts.– wisbuckyJun 19, 2019 at 22:01
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.
-
4The 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. Jun 11, 2015 at 13:41
-
upvoting for saving me the rant, 9 years later, that hasn't changed one bit. it's silly that a "-y" is needed. it's unacceptable that a "-y" is ignored. Jul 28, 2020 at 18:07
-
This is funny and relevant even in 2020. The confirmation is related with the info of data to download / storage required. Something like "Are you sure you would like to spend this amount of data and storage?". And with default configuration, some apt install automatically YES when the package is very small. For example when installing htop. Dec 14, 2020 at 9:59
-
--force-yes
will not only corrupt your system, if you command apt to do that, it will also allow to skip the verification of signatures, posing practical security concerns if used unintentionally. Since expecting or requiring a regular user to read about every detail regarding the application is simply not practical, informing them about the possibly unintended consequences of their command is good practice according to usabilty definitions such as DIN EN ISO 9241-11. Jan 20 at 15:44
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
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.
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
Using yes
is package manager independent. E.g.
yes | apt-get install curl
-
Note that you might run into infinite loops, as yes simply prints
y
to stdin repeatedly till killed or the pipe ceases to exist. Jan 20 at 15:24
Sometimes you need the --allow-downgrades
with the -y
Like sudo apt upgrade -y --allow-downgrades
Because the downgrades are a possibility and the "yes" options is not enough in that cases.