How to ignore or skip dependencies while installing packages on Ubuntu

If you are using an APT package manager to install various packages on Ubuntu, Debian, Linux Mint, Elementary OS, MX Linux, or other similar Linux, then you can ignore or exclude some dependencies which don’t want to be on your system.

For example, lately, I was doing an article on the installation of the Lighttpd web server on Ubuntu 20.04, where I had to skip one dependency or package while installing PHP and its extensions. However, by default, while installing those packages it will also install the apache2 webserver that I didn’t because I already had Lighttpd, thus I want the APT package manager to hold that single Apache2 package while installing the others.

Here is the example:

sudo apt-get install php php-cgi php-cli php-fpm php-curl php-gd php-mysql php-mbstring zip unzip

The following additional packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1
libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 libonig5
php-common php7.4 php7.4-cgi php7.4-cli php7.4-common php7.4-curl php7.4-fpm
php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache
php7.4-readline
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom php-pear
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php7.4 libapr1
libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 libonig5
php php-cgi php-cli php-common php-curl php-fpm php-gd php-mbstring
php-mysql php7.4 php7.4-cgi php7.4-cli php7.4-common php7.4-curl php7.4-fpm
php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache
php7.4-readline
0 upgraded, 32 newly installed, 0 to remove and 43 not upgraded.
Need to get 9,280 kB/9,386 kB of archives.
After this operation, 42.7 MB of additional disk space will be used.
Do you want to continue? [Y/n]

 

In the above output, you can see the Red color text is apache2 which is going to be installed automatically even though I don’t need it. Thus, to exclude that I will use a simple flag that is - Dash, minus or hyphen, whatever you want to call it. Therefore, whatever packages you want to remove, you have to use this - at the end of them while issuing the command.

For example :

In the following command, I want to ignore or exclude the Apache2 package as a dependency.

sudo apt-get install php php-cgi php-cli php-fpm php-curl php-gd php-mysql php-mbstring zip unzip

Then what I will do, I simply type the name of the package with hyphen -. Therefore, the above command will be like this:

sudo apt-get install php php-cgi php-cli php-fpm php-curl php-gd php-mysql php-mbstring zip unzip apache2-

If you want to exclude all packages related to the one you want to exclude, simply give asterisk mark. Let’s say in the above command I want to ignore all packages related to apache2 then I have to add apache2*- at the end of the command with  * and - sign.

And this time the output for the same command will be like this:

You can see it that this time the Apache2 package is not in the list of NEW packages that are going to install. 

Reading state information... Done
Package 'apache2' is not installed, so not removed
unzip is already the newest version (6.0-25ubuntu1).
unzip set to manually installed.
zip is already the newest version (3.0-11build1).
zip set to manually installed.
The following additional packages will be installed:
apache2-bin libapache2-mod-php7.4 libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 libonig5 php-common
php7.4 php7.4-cgi php7.4-cli php7.4-common php7.4-curl php7.4-fpm php7.4-gd
php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom php-pear
Recommended packages:
apache2
The following NEW packages will be installed:
apache2-bin libapache2-mod-php7.4 libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 libonig5 php php-cgi
php-cli php-common php-curl php-fpm php-gd php-mbstring php-mysql php7.4
php7.4-cgi php7.4-cli php7.4-common php7.4-curl php7.4-fpm php7.4-gd
php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline
0 upgraded, 29 newly installed, 0 to remove and 97 not upgraded.
Need to get 8,942 kB/9,048 kB of archives.
After this operation, 40.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Conclusion

Therefore to ignore the dependencies while installing some package using APT package manager, we just need to add a minus sign - at the end of the dependency, you want to exclude.

2 thoughts on “How to ignore or skip dependencies while installing packages on Ubuntu”

  1. Expected less than what I wanted. Linux knows this is a big problem. That is why Linux is not liked on the Desktop. Application creators prefer Windows, Apple & Android.
    The temporary Linux treatment is to try to popularize: appimage, snap or Flatpak. Not mentioned here.
    The other big problems are worse with RPM & AUR Linux systems. There is so much disharmony in Linux, that, as this article shows, only highly trained CLI system administrators should dare use Linux operating systems.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.