Use the --no-install-recommends flag with the apt install command to prevent APT from automatically pulling in suggested dependencies. This ensures a minimal installation by ignoring packages marked as recommended but not strictly required for core functionality, reducing disk usage and potential conflicts.
Understanding Recommended Packages in Debian-Based Systems
In the Debian ecosystem, which includes Ubuntu, package relationships are categorized into several types: Depends, Recommends, Suggests, and Enhances. TheDepends field contains packages that are absolutely necessary for the software to function correctly. If these are missing, the installation will fail or the application may crash. However, the Recommends field is different. It lists packages that the maintainers believe most users will want, but they are not technically required.
By default, modern versions of APT treat Recommends as almost mandatory. When you run a standard installation command, APT resolves the dependency tree, identifies the recommended packages, and installs them alongside your target software. This behavior is designed to provide a seamless user experience out-of-the-box. For example, installing a web browser might also pull in helper utilities for handling specific file types or codecs, even if you do not intend to use them immediately. While this convenience is helpful for desktop environments, it can be undesirable for servers, containers, or users who prefer strict control over their system footprint.
The Command-Line Solution
The most direct way to bypass this automatic behavior is to append the--no-install-recommends option to your installation command. This flag tells APT to ignore the Recommends list entirely during the transaction. You should combine this with the -y flag to automatically answer yes to prompts, ensuring the script runs non-interactively if needed.
sudo apt update
sudo apt install --no-install-recommends -y package-name
Replace package-name with the actual name of the software you wish to install. For instance, if you are installing a text editor like nano, APT might normally suggest installing nano-syntax-highlighting. With the flag above, only the core nano binary will be installed. This method is idempotent and safe; it does not remove existing packages, it only prevents new ones from being added during this specific installation event.
Installing Multiple Packages at Once
You can apply this flag to multiple packages in a single command line. This is efficient when setting up a server environment where you want to minimize bloat across several tools.sudo apt install --no-install-recommends -y nginx mysql-server postgresql
Each package in this list will be installed without its respective recommended dependencies. Note that if two packages share a common dependency listed under Depends rather than Recommends, that shared dependency will still be installed because it is critical for both applications. The --no-install-recommends flag only affects the softer relationship tier.
Configuring APT Permanently
If you frequently need minimal installations and find typing the long flag cumbersome, you can configure APT to behave this way by default. This is done by modifying the configuration files located in/etc/apt/. Specifically, you can create or edit a configuration file in the conf.d directory.
Create a file named 99norecommends inside /etc/apt/apt.conf.d/. Add the following line to this file:
APT::Install-Recommends "false";
This global setting overrides the default behavior for all future apt install commands on the system. You do not need to specify the flag anymore. However, be cautious with this approach. Some graphical applications or complex services rely heavily on recommended packages for full feature parity. Disabling this globally might lead to broken features or missing functionality in certain apps. If you revert to default behavior later, you can simply delete or comment out that line. Alternatively, you can use the --install-recommends flag explicitly when you do want the extra packages.
For more details on customizing APT's interactive behavior, see How to Make APT Install Always Ask for Confirmation?. This complements the current discussion by allowing you to control whether APT prompts you before making changes, adding another layer of safety to your package management workflow.
Downloading Packages Without Installing
Sometimes you may need to acquire the .deb files for offline installation or inspection without triggering any dependency resolution at all. In such cases, you can use the--download-only flag. This fetches the binaries but does not unpack or configure them.
sudo apt install --download-only --no-install-recommends package-name
This is useful for air-gapped systems or when building custom images. For a deeper dive into managing deb files across different architectures, refer to Download .deb packages for different os version + architecture with apt. Understanding how to handle these files manually gives you complete control over what enters your system, independent of APT's automated recommendation engine.
Verifying What Was Installed
After installation, it is good practice to verify that no unwanted packages were pulled in. You can check the history of transactions usingapt-mark showmanual to see manually installed packages versus those marked as automatically installed.
apt-mark showauto | grep package-name
If the recommended packages were ignored, they should not appear in the auto-installed list unless they were hard dependencies. You can also review the log file at /var/log/apt/history.log to see exactly which packages were processed during the last transaction. This transparency helps in auditing your system for security and performance reasons.
Frequently Asked Questions
Will removing recommended packages break my application?
Generally, no. By definition, recommended packages are not required for the core application to run. However, some features might be missing or less functional if a recommended helper utility is absent. Always test critical functionality after a minimal install.How do I reinstall the recommended packages later?
You can force APT to install them by runningsudo apt install package-name without the --no-install-recommends flag. Since the main package is already present, APT will identify the missing recommendations and offer to install them.
Does this flag affect Dependent packages?
No. The--no-install-recommends flag only ignores the Recommends relationship. All packages listed under Depends, Pre-Depends, and Conflicts will still be resolved and installed as necessary.