Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make APT assume yes and force yes for all installations in a Bash script

Tags:

bash

apt

apt-get

I'm currently getting into Linux and want to write a Bash script which sets up a new machine just the way I want it to be.

In order to do that I want to install different things on it, etc.

What I'm trying to achieve here is to have a setting at the top of the Bash script which will make APT accept all [y/n] questions asked during the execution of the script.

A question example I want to automatically accept:

After this operation, 1092 kB of additional disk space will be used. Do you want to continue? [Y/n]

I just started creating the file, so here is what I have so far:

#!/bin/bash

# Constants

# Set APT to accept all [y/n] questions
>> some setting here <<

# Update and upgrade APT
apt update;
apt full-upgrade;

# Install terminator
apt install terminator
like image 513
Chris Avatar asked Dec 28 '25 18:12

Chris


1 Answers

apt is meant to be used interactively. If you want to automate things, look at apt-get, and in particular its -y option:

-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 an unauthenticated package or removing an essential package occurs then apt-get will abort. Configuration Item: APT::Get::Assume-Yes.

See also man apt-get for many more options.

like image 124
mivk Avatar answered Dec 31 '25 11:12

mivk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!