Package managers like apt-get are designed to maintain system stability by automatically resolving dependencies. However, there are legitimate cases where we need to bypass this behavior:
# Typical mailx installation pulls unwanted dependencies
sudo apt-get install mailx
# Installs: mailx, exim4-base, exim4-config, exim4-daemon-light...
The most straightforward approach combines two flags:
sudo apt-get --no-install-recommends --ignore-depends=exim4 mailx
Key parameters:
- --no-install-recommends: Skips recommended packages
- --ignore-depends: Explicitly ignores listed dependencies
When apt-get refuses to cooperate, we can manually download and force-install:
# Download package without installing
apt-get download mailx
# Force install ignoring dependencies
sudo dpkg --force-depends -i mailx*.deb
# Fix potential broken dependencies
sudo apt-get -f install
For persistent dependency management:
# Install equivs
sudo apt-get install equivs
# Create dummy package
equivs-control nomailx-deps
# Edit control file to provide virtual dependencies
# Then build and install:
equivs-build nomailx-deps
sudo dpkg -i nomailx-deps.deb
Here's how I configured my production server:
# First purge any existing MTA
sudo apt-get purge exim4*
# Then install mailx without dragging exim4
sudo apt-get --no-install-recommends \
--ignore-depends=exim4,exim4-base \
install mailx
# Verify mailx works with Postfix
echo "Test" | mailx -s "Test Subject" user@example.com
- Breaking dependencies can lead to unstable systems
- Some packages genuinely require their dependencies
- Always test in development environments first
- Document your overrides for future maintenance
The key is finding balance between system purity and practical needs. While these methods work, they should be used judiciously.
Package managers like apt-get are fantastic for handling dependencies automatically, but sometimes this automation works against us. Take this common scenario: you want to install mailx
for basic email functionality, but apt insists on pulling in exim4
or other MTA packages you don't need (especially when you're already running Postfix or Sendmail).
The most straightforward approach is using apt's built-in flag to skip recommended packages:
sudo apt-get install --no-install-recommends mailx
This tells apt to only install strictly required dependencies, not the "recommended" ones that often include unnecessary extras.
For more granular control, you can use dpkg to override dependencies:
sudo dpkg --force-depends -i package.deb
Follow this with:
sudo apt-get install -f
This method should be used sparingly as it can leave your system in an inconsistent state.
Another approach is to explicitly hold problematic dependencies:
sudo apt-mark hold exim4-daemon-light exim4-config exim4-base sudo apt-get install mailx
Advanced users can create apt preferences to pin certain packages:
Package: exim4* Pin: release * Pin-Priority: -1
Save this to /etc/apt/preferences.d/exclude-exim.pref
When all else fails, you can compile from source while specifying build options to exclude unwanted features:
apt-get source mailx cd mailx-* ./configure --without-exim make sudo checkinstall
After any of these methods, verify that mailx works with your existing MTA:
echo "Test email body" | mailx -s "Test Subject" user@example.com
Check your mail logs to confirm the message was properly routed through your preferred MTA.