109

I am trying to write a bash script to install a list of software. I am using --assume-yes to get past the prompts.

This following line somehow doesn't work:

sudo apt-get install python-software-properties --assume-yes

If I try to apt-get without --assume-yes it works but the prompt asks me to:

please [Enter] to continue or ctrl+c to cancel adding it

How do I add Enter as a command when running apt-get install instead of using --assume-yes?

Braiam
  • 67,791
  • 32
  • 179
  • 269
Rengas
  • 1,281
  • 2
  • 8
  • 10

3 Answers3

142

Your problem is that the option should be before the packages, not after, this is the correct syntax:

apt-get <options> command package=version/release

So, for it to work it should be:

sudo apt-get --assume-yes install python-software-properties

apt-get is forgiving when mixing up command and options, but to err on the safe side, you should always use the options before the command and never put options or commands after the name of the package.

Braiam
  • 67,791
  • 32
  • 179
  • 269
75

Add -y flag to apt-get install <package-name> command like below, you won't get any prompt while installing packages.

sudo apt-get install -y <package-name>

From apt-get --help

-y  Assume Yes to all queries and do not prompt
Avinash Raj
  • 78,556
  • 6
    @PeterMortensen they do the same thing. From the man page:-y, --yes, --assume-yes Automatic yes to prompts – davejagoda Dec 06 '17 at 18:59
  • 3
    Note that this may not be enough and you may also need to add -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" to your commands. See https://raphaelhertzog.com/2010/09/21/debian-conffile-configuration-file-managed-by-dpkg/ for details. – TTimo Oct 10 '19 at 15:45
  • @TTimo Wow! 6 days after you posted that comment, I come along and find that's exactly the answer I needed!! If I could upvote your comment more I would! – ckhatton Oct 16 '19 at 07:00
  • Feel free to edit the answer with additional options. – Avinash Raj Oct 16 '19 at 07:09
7

For another silent and effective way as follows :

sudo DEBIAN_FRONTEND=noninteractive apt-get install -qq python-software-properties < /dev/null > /dev/null