117

When installing software in debian systems we can put something like this:

sudo apt-get install -y chromium-browser

that way the installation occurs automatically, whitout asking to confirm installation [Y/n]. Can i do the same with pacman?

daisy
  • 54,555
JohannRamos
  • 1,311

2 Answers2

157

From man pacman:

--noconfirm
Bypass any and all “Are you sure?” messages. It’s not a good idea to do this unless you want to run pacman from a script.

Note the qualification about using this with care...

Arch is a rolling release, which means pacman has to, from time to time, manage some quite complex upgrades. At these times pacman will prompt you to confirm your choices—disregarding these prompts will generally not be a significant issue, but in some cases, as with the recent move from /lib to /usr/lib , a lack of attention will cause major breakage. This is a not a habit you want to cultivate.

jasonwryan
  • 73,126
  • I've never run pacman with the "--noconfirm" in about 3 years of using Arch, because of that warning. How many people run pacman from a script? What are the big risks? I have had to intervene 3 or 4 times to fix things that pacman has refused to upgrade. –  Oct 19 '12 at 03:18
  • 5
    I assume, given Arch's culture, that the warning is there to discourage complacency and the misguided notion that automating pacman updates is a good idea. A lot of breakage can be put down to people not reading pacman's output; --noconfirm would exacerbate that... – jasonwryan Oct 19 '12 at 03:31
  • 2
    I have an "install" script that uses --noconfirm. The idea is to be able to take a system with a recently updated clean install and make it "usable" without any user interaction. – StrongBad Oct 19 '12 at 09:42
  • The idea is to install software from a script without any user interaction, so this is perfect. Thanks! – JohannRamos Oct 19 '12 at 12:52
  • @jasonwryan - I have been trying to generate a silent server setup script for msys2 (future of msysgit) on Windows 8. It emulates arch linux / pacman. I've been unable to get pacman -S --noconfirm --needed bash pacman pacman-mirrors msys2-runtime to execute without prompting me if I want to install. I'm curious if I'm doing something incorrect or if this is just a bug in the port? Any ideas would be welcome... – cchamberlain May 08 '15 at 03:59
  • @ColeChamberlain that command shouldn't generate a prompt. – jasonwryan May 08 '15 at 04:23
  • @jasonwryan - Thanks for the response! If I can figure it out maybe I'll submit a pull request to the project. – cchamberlain May 08 '15 at 04:24
  • @JohannRamos I've done a script myself, to automatize the installing of an AUR helper. Besides using --noconfirm, I also used the --needed flag. That skips installing packages already installed and up to date. You might want to use that as well. EDIT: just noticed that cchamberlain used that flag in his line. – Jeffrey Lebowski Jun 02 '16 at 12:55
  • 25
    Actually, --noconfirm doesn't assume yes, instead it assumes the default answer, which is quite often no. Example:
    Cache directory: /var/cache/pacman/pkg/
    :: Do you want to remove ALL files from cache? [y/N]```
    For the case above, `yes|pacman -Scc` assumes `yes`
    
    – Utgarda Sep 26 '17 at 10:30
  • 16
    Actually, pacman --noconfirm is required if you are using a Docker container, otherwise, it will just wait for an input, and thus shutting down the container with an error. – Amin NAIRI Mar 31 '19 at 19:12
  • pamac has "--no-confirm" so it is not that easy to remember.. – 16851556 Nov 11 '20 at 16:37
  • Actually, even --noconfirm will not work for certain conflicts, such as Replace package with extra/package? [Y/n]. Instead, it print package conflicts can not be resolved with noconfirm, aborting, then die with status 1. – Matt Alexander Sep 28 '22 at 04:05
65

While the manpage on the matter is not very clear, the --noconfirm flag will not assume "yes" on every answer. It assumes the default answer which can be "no" sometimes.

--noconfirm
      Bypass any and all “Are you sure?” messages. It’s not a good idea
      to do this unless you want to run pacman from a script

To assume "yes", you could pipe the output of the yes command to pacman.

yes | sudo pacman -S firefox
  • 8
    Use yes | LC_ALL=en_US.UTF-8 pacman [...] for compatibility with systems whose language is not set to English. Otherwise the [Y/n] questions become [J/n], for example. – ComFreek Jul 20 '18 at 06:48
  • 11
    Also beware this answer fails if Pacman ever asks a question without a y answer, e.g. Enter a selection (default=all). – ComFreek Jul 20 '18 at 06:58
  • @ComFreek, rather than altering the environment variables passed to pacman, it would be easier, and probably safer to just to do yes J | sudo pacman -S firefox in that case. yes J will cause yes to repeatidly output a J instead of a y. – Drew Chapin Jan 12 '19 at 16:20
  • 3
    "and probably safer" How so? The override above only affects the environment of the process (tree) spawned and ends with it. Furthermore, the invocation above is exactly the same for all locales. – kelvin Sep 16 '19 at 17:03
  • Also, what if someone copy/pastes one such command line but has a locale in which one of the options has the opposite or a completely different meaning? Example: J (or Y) meaning "no" or "all". – kelvin Sep 16 '19 at 17:13
  • Works fine in MSYS2 (Windows). – Henke - Нава́льный П с м Nov 30 '20 at 14:28
  • @ComFreek you can go around an "Enter a selection" prompt by piping multiple commands one after another. Let's say you have 2 prompts for specifying which packages from a group to install; in that case you can use (echo "1 2 6-5"; echo "3 4 8"; yes J) | sudo pacman -S kf5 kf5aids – Architector 4 Jun 06 '21 at 11:12
  • @ComFreek yes '' would output empty lines, so yes '' | pacman ... should select the default in any prompt and work in any locale. – JoL Jul 20 '22 at 06:39