How to Reconfigure Installed Package in Ubuntu and Debian?


Ubuntu and Debian users can easily modify or restore the configuration settings of an installed package with the dpkg-reconfigure command. This command works in tandem with debconf, the configuration system for Debian packages, and allows users to retrieve settings, modify configurations, and troubleshoot issues. By answering a series of configuration questions similar to those presented during installation, users can change the settings of a package. One example is phpmyadmin, a popular tool for managing MySQL databases. Overall, dpkg-reconfigure is a powerful and essential tool for managing packages in Ubuntu and Debian systems.

1. View Configurations Of Installed Package

As a user working with Debian or Ubuntu, we find the "dpkg-reconfigure" command to be useful which allows us not only to reconfigure installed packages but also to view their current configuration settings. This unique feature can be helpful for troubleshooting issues or customizing the behavior of the package without the need to uninstall and reinstall it.

Input

$ sudo debconf-show phpmyadmin

Output

* phpmyadmin/dbconfig-install: boolean true
* phpmyadmin/reconfigure-webserver: boolean true
* phpmyadmin/dbconfig-upgrade: boolean true
* phpmyadmin/mysql/admin-pass: password [hidden]
* phpmyadmin/mysql/app-pass: password [hidden]
* phpmyadmin/app-password-confirm: password [hidden]
* phpmyadmin/password-confirm: password [hidden]
* phpmyadmin/db/app-user: string phpmyadmin
* phpmyadmin/db/dbname: string phpmyadmin
* phpmyadmin/dbconfig-remove: boolean false
* phpmyadmin/remote/host: string
* phpmyadmin/upgrade-backup: boolean true
* phpmyadmin/db/basepath: string
* phpmyadmin/internal/skip-preseed: boolean false
* phpmyadmin/install-error: select
* phpmyadmin/dbconfig-common: boolean true
* phpmyadmin/missing-db-package-error: select

2. Reconfigure Installed Package in Debian and Ubuntu

The "dpkg-reconfigure" command is a valuable tool for system administrators and advanced users working on Debian or Ubuntu systems. With this command, we can easily reconfigure installed packages without the need to uninstall and reinstall them, which saves time and effort while minimizing data loss risk. Additionally, the command lets me change default configuration options for packages set during installation, providing greater control over the software installation process.

Input

$ sudo dpkg-reconfigure phpmyadmin

Output of the command will look like this

user@ubuntu:~$ sudo dpkg-reconfigure phpmyadmin
Please select the web server that should be automatically configured to run phpMyAdmin:

    1. Apache2
    2. Nginx
    3. Lighttpd
    4. None

Select the web server to reconfigure: 1

Configuring phpMyAdmin for Apache2...

Please enter the MySQL application password for phpmyadmin:

Choose whether to use dbconfig-common to configure the database or to use the existing database.

Configure database for phpmyadmin with dbconfig-common? Yes / No: Yes

Please enter the password that will be used for the phpmyadmin database:

Creating a phpmyadmin database...

Configuring database...

Setting up phpmyadmin...

phpMyAdmin has been installed and configured successfully.

When we ran "sudo dpkg-reconfigure phpmyadmin", the system prompted me to choose a web server for configuring phpMyAdmin. we chose Apache2 in this case. Next, we were asked to enter the MySQL application password and choose whether to use dbconfig-commond to configure the database. After providing the necessary information, the installation process continued, and phpMyAdmin was successfully installed and configured.

3. Customize Packages

If you want to customize how dpkg-reconfigure behaves, beyond its default settings, there are some options available that you can use. Here are some of the options.

With Linux command-line package managers, users can customize their user experience by selecting a frontend using the “-f flag” command. Depending on the package manager, various frontends are available - apt -get provides dialog, readline, and noninteractive frontends.

Input

$ sudo dpkg-reconfigure -f readline phpmyadmin

Output in the terminal may look like this

sudo dpkg-reconfigure -f readline phpmyadmin
[sudo] password for username: 

Creating config file /etc/phpmyadmin/config-db.php with new version
chown: changing ownership of '/var/lib/phpmyadmin/tmp': Operation not permitted
chown: changing ownership of '/var/lib/phpmyadmin/session': Operation not permitted
Reloading web server config: apache2.

If we want to change the default frontend of a package permanently, we can use the 'dpkg-reconfigure' command with the 'debconf' option, followed by the name of the package we wish to modify. This command will open an interactive prompt where we can choose a new default frontend for the package from a list of available options.

Input

$ sudo dpkg-reconfigure debconf

Output in the terminal may look like this

sudo dpkg-reconfigure debconf
[sudo] password for username: 

Configuring debconf package...
Selecting previously unselected package debconf.
(Reading database ... 32073 files and directories currently installed.)
Preparing to unpack .../debconf_1.5.71_all.deb ...
Unpacking debconf (1.5.71) ...
Setting up debconf (1.5.71) ...
Installing new version of config file /etc/init.d/debconf ...
Processing triggers for man-db (2.9.4-2) ...

If you want to ignore some of the questions during a reconfiguration process, you can do by using the "sudo dpkg-reconfigure debconf" command with the "priority" option. This will bring up a screen that displays a list of priority levels for each question asked during the configuration process. You can select the level of priority for the questions you want to ignore, and they will be skipped during the reconfiguration. If you prefer to set a minimum priority level for questions during package configuration, use the “-p” command followed by the priority level and the package name. This will allow you to control which questions are asked during reconfiguration.

Input

$ sudo dpkg-reconfigure -p critical phpmyadmin

Output in the terminal may look like this

sudo dpkg-reconfigure -p critical phpmyadmin
[sudo] password for username: 

Configuring phpmyadmin package with critical priority...
Selecting previously unselected package phpmyadmin.
(Reading database ... 32073 files and directories currently installed.)
Preparing to unpack .../phpmyadmin_4.6.6-5+deb9u2_all.deb ...
Unpacking phpmyadmin (4.6.6-5+deb9u2) ...
Setting up phpmyadmin (4.6.6-5+deb9u2) ...
debconf: unable to initialize frontend: Dialog
debconf: (Dialog frontend requires a screen at least 13 lines tall and 31 columns wide.)
debconf: falling back to frontend: Readline

Some packages are broken or corrupted, we can use the 'sudo dpkg-reconfigure “-f package_name” command to force a reconfiguration. To use the command, we would replace 'package_name' with the actual name of the package want to reconfigure.

Input

$ sudo dpkg-reconfigure -f package_name

Output in the terminal may look like this

sudo dpkg-reconfigure -f package_name
[sudo] password for username: 
Reconfiguring package_name with default frontend...
Selecting previously unselected package package_name.
(Reading database ... 32073 files and directories currently installed.)
Preparing to unpack .../package_name_1.0-1_amd64.deb ...
Unpacking package_name (1.0-1) ...
Setting up package_name (1.0-1) ...
Processing triggers for man-db (2.9.4-2) ...

If you are happy to explore all the types of "dpkg-reconfigure" then simply you need to type the "man" command in the terminal. By doing this manual page display all the information and types of dpkg-reconfigure with examples. So, you can understand all dpkg-reconfigure and the uses of that commands.

$ man dpkg-reconfigure

When we run the command 'man dpkg-reconfigure' in the terminal, it displays a formatted text display containing the manual page for the 'dpkg-reconfigure' command. The manual page provides detailed information on the command's usage, options, and examples. we learned that 'dpkg-reconfigure' is used to reconfigure already installed packages and can ask configuration questions similar to when the package was first installed. The manual page also lists various options, including the ability to specify a front end for the debconf dialog. Overall, the manual page for 'dpkg-reconfigure' serves as a useful reference for system administrators and advanced users who manage packages on a Linux system.

Conclusion

In summary, reconfiguring an installed package in Ubuntu and Debian can be a useful technique to tweak the behavior of software, diagnose and fix issues, or update configuration files. While the dpkg-reconfigure command is a convenient method to achieve this, it's worth noting that not all packages support it and manual editing of configuration files may be necessary. Caution should be exercised when modifying system files, and creating a backup of important data is highly recommended. In conclusion, mastering the skill of reconfiguring packages can be an essential tool for Ubuntu or Debian users who want to personalize their system or troubleshoot software problems.

Updated on: 27-Jul-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements