When working with apt-get
in Debian/Ubuntu systems, the -qq
flag is a powerful yet often overlooked option for silent operations. This double quiet flag suppresses almost all output from apt-get
, making it particularly useful in automation scripts.
# Basic usage examples:
apt-get update -qq
apt-get install -qq -y package_name
The combination of -qq
and output redirection (> /dev/null
) serves different purposes:
# -qq alone:
apt-get update -qq # Only shows critical errors
# With output redirection:
apt-get update > /dev/null # Redirects all output but still processes messages internally
Here's how you might use these flags in various scenarios:
# In provisioning scripts (like Vagrant):
#!/bin/bash
apt-get update -qq > /dev/null
apt-get install -qq -y apache2 mysql-server > /dev/null
# In CI/CD pipelines:
- name: Install dependencies
run: sudo apt-get update -qq && sudo apt-get install -qq -y build-essential
While -qq
makes operations silent, it doesn't necessarily make them faster. The real performance benefit comes from combining it with -y
(auto-confirm) to create completely non-interactive installations:
# Optimal silent installation:
apt-get update -qq && \
apt-get install -qq -y --no-install-recommends \
package1 \
package2 \
package3
For even quieter operations, consider these alternatives:
# Using DEBIAN_FRONTEND (for Debian-based systems):
DEBIAN_FRONTEND=noninteractive apt-get -qq -y install package
# Using apt instead of apt-get (newer systems):
apt -qq -y update && apt -qq -y install package
Since -qq
suppresses output, proper error handling becomes crucial:
#!/bin/bash
if ! apt-get update -qq; then
echo "Update failed" >&2
exit 1
fi
if ! apt-get install -qq -y package; then
echo "Installation failed" >&2
exit 1
fi
Avoid -qq
in these situations:
# When debugging installation issues
# When you need to see progress indicators
# When users might need to interact with the process
While reviewing a Vagrantfile
provisioning script for an Ubuntu environment, I encountered this pattern:
apt-get update -qq > /dev/null
apt-get -qq -y install apache2 > /dev/null
The -qq
flag stands for "very quiet" mode in apt-get
. It's actually a doubled -q
(quiet) flag, with increasing levels of suppression:
-q
(single): Shows only critical output-qq
(double): Shows almost nothing (error messages only)
This differs from output redirection (> /dev/null
) in several key ways:
# Different suppression techniques comparison:
apt-get install package # Normal verbose output
apt-get -q install package # Shows only critical messages
apt-get -qq install package # Shows only fatal errors
apt-get install package > /dev/null # Silences ALL output including errors
The combination -qq -y
is particularly common in automated deployment scenarios because:
- It prevents unnecessary output during automated processes
- It still allows error messages to surface (unlike pure
/dev/null
redirection) - It works well with CI/CD pipelines where excessive output can cause issues
Here's a more complete provisioning example:
#!/bin/bash
# Silent package installation with error handling
if ! apt-get update -qq; then
echo "Failed to update package lists" >&2
exit 1
fi
if ! apt-get -qq -y install nginx mysql-server; then
echo "Package installation failed" >&2
exit 1
fi
When implementing silent package management:
# Good:
apt-get -qq -y install package || exit 1
# Better (captures stderr separately):
apt-get -qq -y install package 2>error.log || {
cat error.log >&2
exit 1
}
# Best (Dockerfile example):
RUN apt-get update -qq \
&& apt-get install -qq -y --no-install-recommends \
build-essential \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*