APT::Get::Assume-Yes option to false in your system settings. This can be achieved by creating a dedicated configuration file in the /etc/apt/apt.conf.d/ directory or by using environment variables for temporary sessions. By setting this flag explicitly, you prevent automated scripts or accidental commands from silently installing packages and their dependencies without your explicit approval, thereby adding a critical layer of safety to your package management workflow on Ubuntu and Debian systems.
Understanding APT Confirmation Behavior
By default, many Linux distributions are configured to skip confirmation prompts when running standard update or upgrade commands via cron jobs or unattended-upgrades services. While this is efficient for server maintenance, it poses a security risk on desktop environments where manual oversight is preferred. The Advanced Package Tool (APT) uses a configuration hierarchy to determine its behavior, allowing users to override default flags at various levels. When you run a command likeapt install, APT checks for the -y or --yes flag. If present, it assumes yes to all questions. If absent, it typically asks for confirmation unless another configuration directive overrides this interaction. Understanding how these flags interact with system-wide configurations is essential for enforcing strict confirmation policies.
Method 1: System-Wide Configuration File
The most robust way to enforce confirmation across all user accounts and scripts is to create a persistent configuration file. This method ensures that even if a user forgets to add the-n flag, the system will still pause for input.
Create a new configuration file in the /etc/apt/apt.conf.d/ directory. You can name it something descriptive, such as 99-force-confirm. Use a text editor with root privileges to write the following line into this file:
APT::Get::Assume-Yes "false";
This directive tells APT to treat the --assume-yes flag as false unless explicitly overridden by a command-line argument. If you want to ensure that no script can accidentally bypass this, you can also set APT::Get::Show-Upgraded to true to see exactly what is being changed before confirming.
After saving the file, verify the configuration by running a dry-run installation. This allows you to see how APT would behave without actually making changes. Run the following command:
sudo apt install -s <package-name>
If the configuration is correct, APT should not automatically assume yes, although dry-runs sometimes suppress interactive prompts depending on the version. To test the actual interactive behavior, try installing a small package without the -y flag and observe if the prompt appears.
Method 2: Using Aliases for User Convenience
For users who prefer not to modify system-wide settings, creating shell aliases is an effective alternative. This approach requires discipline but offers flexibility. You can define aliases in your~/.bashrc or ~/.zshrc file that automatically append the -n (no) flag to common installation commands.
Add the following lines to your shell configuration file:
alias apti='apt install -n'
alias aptu='apt upgrade -n'
After editing the file, reload your shell configuration by running source ~/.bashrc. Now, whenever you type apti instead of apt install, the system will ask for confirmation. This method is particularly useful for developers who frequently switch between automation scripts and manual installations.
However, note that this does not protect against direct usage of apt install without the alias. For complete protection, Method 1 is superior because it operates at the package manager level rather than the shell level.
Related Configuration Options
Beyond forcing confirmation, you might want to refine how APT handles dependencies. For instance, some users prefer to avoid installing recommended packages to keep their system minimal. If you are interested in controlling dependency resolution alongside confirmation prompts, you may find our guide on Installing Specific Packages without Recommended Ones using apt helpful. This complements the confirmation strategy by giving you granular control over what gets installed once you say yes. Additionally, if you encounter errors while managing packages, such as broken dependencies or dpkg failures, understanding how to fix them is crucial. A common issue is the error code returned by dpkg, which can halt installations. Refer to our article on Fixing E: Sub-process /usr/bin/dpkg returned an error code (1) on Kali Linux for troubleshooting steps that apply to Debian-based systems generally.Verifying Your Settings
To ensure your changes have taken effect, you can query the current APT configuration directly. Use theapt-config command to dump specific settings. For example, to check the assume-yes setting, run:
apt-config dump | grep Assume-Yes
You should see output similar to APT::Get::Assume-Yes "false";. If you do not see this, or if it shows true, check your configuration files in /etc/apt/apt.conf.d/ for any conflicting entries. Files with higher numbers in their names often take precedence, so ensure your confirmation file has a high enough number, like 99, to override defaults.
Frequently Asked Questions
Will this affect unattended-upgrades?
Yes, if you set APT::Get::Assume-Yes to false globally, it may interfere with automated updates that rely on silent execution. Unattended-upgrades typically uses its own configuration in /etc/apt/apt.conf.d/50unattended-upgrades, but it is best to test this change carefully on non-critical systems first to ensure automated maintenance scripts do not fail.
How do I temporarily bypass the confirmation prompt?
You can always override the system configuration by appending the -y or --yes flag to your APT command. For example, sudo apt install -y <package> will proceed without asking for confirmation, regardless of the global settings. This is useful for scripting or when you are certain about the installation.
Does this work for snap or flatpak packages?
No, this configuration only affects APT, which manages .deb packages. Snap and Flatpak use different package managers (snap and flatpak) with their own separate confirmation behaviors. You would need to configure those tools independently if you wish to enforce confirmation for them as well.
What happens if I miss the confirmation prompt?
If you are in an interactive terminal and miss the prompt, the process will simply wait indefinitely until you provide input or cancel it with Ctrl+C. In headless environments or scripts, this can cause timeouts. Always ensure you are present at the terminal when running interactive APT commands after enabling this feature.
Can I reset this setting easily?
Yes, simply delete or rename the configuration file you created in /etc/apt/apt.conf.d/. For example, renaming 99-force-confirm to 99-force-confirm.bak will disable the rule immediately. Alternatively, you can edit the file and change the value back to true or remove the line entirely.