How to Use Ubuntu Server dpkg-reconfigure to Repair Broken Packages

When you use the standard apt-get install command to install a piece of software on Ubuntu Server (such as postfix or tzdata), the system often presents a series of interactive, text-based menus asking you how you want to configure the software. If you accidentally hit “Enter” on the wrong screen, or if you simply need to change those core settings months later, you cannot always just edit a text file in /etc/. Many packages rely on complex post-installation scripts to generate those configuration files dynamically. To safely run those configuration wizards again, you must use the dpkg-reconfigure command.

What is dpkg-reconfigure?

While apt is the high-level package manager that downloads software from the internet and resolves dependencies, dpkg is the underlying tool that actually unpacks and installs the .deb files. The dpkg-reconfigure utility tells the system to execute a package’s configuration scripts exactly as it did during the initial installation.

Step 1: Identify the Package Name

You must know the exact name of the package you want to reconfigure. If you are trying to change the server’s time zone, the package is tzdata. If you want to change how the keyboard maps special characters, the package is keyboard-configuration.

If you are unsure of the exact name, you can search for installed packages using dpkg -l:

dpkg -l | grep ssh

Step 2: Run the Reconfiguration

You must run this command as root (using sudo), because the post-installation scripts will be modifying system-level files and restarting background daemons.

To completely reset the server’s timezone configuration:

sudo dpkg-reconfigure tzdata

Instead of a standard terminal prompt, the screen will switch to an interactive ncurses interface (a blue or grey text-based menu). You can use your arrow keys to select a geographic area (e.g., America), press Enter, and then select a specific city (e.g., New York). Once you finish, the utility will automatically rewrite the /etc/timezone and /etc/localtime files and restart the system logging service to apply the change.

Step 3: Repairing Broken Postfix Configurations

A classic use case for dpkg-reconfigure involves the Postfix mail server. During installation, Postfix asks if it should act as an “Internet Site,” a “Satellite system,” or “Local only.” If you choose the wrong one, emails will silently fail to send.

Instead of trying to manually edit the dense /etc/postfix/main.cf file, simply run:

sudo dpkg-reconfigure postfix

The wizard will walk you through setting the System mail name, the relay host, and the local network subnets, perfectly formatting the complex configuration file for you.

Step 4: Non-Interactive Mode (For Scripts)

If you are writing a bash script to provision 100 new Ubuntu Servers automatically, you cannot have the script stop and wait for a human to press the arrow keys in a blue menu.

You can force dpkg-reconfigure to run non-interactively using the -f noninteractive flag. However, for this to work, you must first pre-seed the answers to the configuration questions using the debconf-set-selections tool.

echo "tzdata tzdata/Areas select America" | sudo debconf-set-selections
echo "tzdata tzdata/Zones/America select New_York" | sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive tzdata

This allows for completely silent, automated repairs and configurations across massive server farms.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.