APT – Fixing Unexpected Removal of Firefox During apt-get Install

aptpackage-management

I executed the command:

$ sudo apt-get install ssh-import-id

The output was (as people in the comments asked providing it comletely):

$ sudo apt-get install ssh-import-id
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gdbserver gstreamer1.0-gtk3 libabw-0.1-1 libatkmm-1.6-1v5 libbabeltrace1 libc6-dbg libcairomm-1.0-1v5 libcdr-0.1-1
  libcolamd2 libdw1 libe-book-0.1-1 libepubgen-0.1-1 libetonyek-0.1-1 libfreehand-0.1-1 libglibmm-2.4-1v5 libgtkmm-2.4-1v5
  libilmbase12 libmspub-0.1-1 libmwaw-0.3-3 libnuma1 libodfgen-0.1-1 libopenexr22 libpangomm-1.4-1v5 libsuitesparseconfig5
  libvisio-0.1-1 libwpd-0.10-10 libwpg-0.3-3 libwps-0.4-4 libxss1 libxvmc1 lp-solve vim-common x11-apps x11-session-utils
  xbitmaps xinit xserver-xorg-video-amdgpu-hwe-18.04 xserver-xorg-video-ati-hwe-18.04 xserver-xorg-video-fbdev-hwe-18.04
  xserver-xorg-video-intel-hwe-18.04 xserver-xorg-video-nouveau-hwe-18.04 xserver-xorg-video-qxl-hwe-18.04
  xserver-xorg-video-radeon-hwe-18.04 xserver-xorg-video-vesa-hwe-18.04 xxd
Use 'sudo apt autoremove' to remove them.
Recommended packages:
  openssh-server
The following packages will be REMOVED:
  brltty firefox gdb google-chrome-stable gparted irqbalance libcc1-0 libglu1-mesa libllvm6.0 libmagickcore-6.q16-3-extra
  libpagemaker-0.0-0 libproxy1-plugin-gsettings libreoffice-avmedia-backend-gstreamer libreoffice-base-core libreoffice-calc
  libreoffice-draw libreoffice-gnome libreoffice-gtk3 libreoffice-help-en-us libreoffice-impress libreoffice-math
  libreoffice-ogltrans libreoffice-writer libxatracker2 lshw printer-driver-brlaser printer-driver-splix thermald
  ubuntu-desktop ubuntu-minimal ubuntu-standard vim-tiny xorg xserver-xorg-video-all-hwe-18.04
  xserver-xorg-video-vmware-hwe-18.04 zeitgeist-core
The following NEW packages will be installed:
  ssh-import-id
0 upgraded, 1 newly installed, 36 to remove and 0 not upgraded.
Need to get 10,4 kB of archives.
After this operation, 595 MB disk space will be freed.
Do you want to continue? [Y/n] Y
Get:1 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 ssh-import-id all 5.7-0ubuntu1 [10,4 kB]
Fetched 10,4 kB in 1s (14,5 kB/s)                      
(Reading database ... 127288 files and directories currently installed.)
Removing brltty (5.5-4ubuntu2.0.1) ...
Removing firefox (68.0.1+build1-0ubuntu0.18.04.1) ...
Removing gdb (8.1-0ubuntu3) ...
Removing google-chrome-stable (76.0.3809.100-1) ...
Removing gparted (0.30.0-3ubuntu1) ...
Removing irqbalance (1.3.0-0.1ubuntu0.18.04.1) ...
Removing libcc1-0:amd64 (8.3.0-6ubuntu1~18.04.1) ...
Removing ubuntu-desktop (1.417.3) ...
Removing xorg (1:7.7+19ubuntu7.1) ...
Removing libglu1-mesa:amd64 (9.0.0-2.1build1) ...
Removing xserver-xorg-video-all-hwe-18.04 (1:7.7+19ubuntu8~18.04.2) ...
Removing xserver-xorg-video-vmware-hwe-18.04 (1:13.3.0-2build1~18.04.1) ...
Removing libxatracker2:amd64 (19.0.2-1ubuntu1.1~18.04.2) ...
Removing libllvm6.0:amd64 (1:6.0-1ubuntu2) ...
Removing libmagickcore-6.q16-3-extra:amd64 (8:6.9.7.4+dfsg-16ubuntu6.7) ...
Removing libreoffice-ogltrans (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libreoffice-impress (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libreoffice-draw (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libpagemaker-0.0-0:amd64 (0.0.4-1) ...
Removing libproxy1-plugin-gsettings:amd64 (0.4.15-1) ...
Removing libreoffice-avmedia-backend-gstreamer (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libreoffice-help-en-us (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libreoffice-writer (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libreoffice-calc (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libreoffice-base-core (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libreoffice-gnome (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libreoffice-gtk3 (1:6.0.7-0ubuntu0.18.04.8) ...
Removing libreoffice-math (1:6.0.7-0ubuntu0.18.04.8) ...
Removing ubuntu-standard (1.417.3) ...
Removing lshw (02.18-0.1ubuntu6.18.04.1) ...
Removing printer-driver-brlaser (4-1) ...
Removing printer-driver-splix (2.0.0+svn315-6fakesync1) ...
Removing thermald (1.7.0-5ubuntu2) ...
Removing ubuntu-minimal (1.417.3) ...
Removing vim-tiny (2:8.0.1453-1ubuntu1.1) ...
Removing zeitgeist-core (1.0-0.1ubuntu1) ...
Selecting previously unselected package ssh-import-id.
(Reading database ... 126362 files and directories currently installed.)
Preparing to unpack .../ssh-import-id_5.7-0ubuntu1_all.deb ...
Unpacking ssh-import-id (5.7-0ubuntu1) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Processing triggers for libreoffice-common (1:6.0.7-0ubuntu0.18.04.8) ...
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) ...
Processing triggers for cups (2.2.7-1ubuntu2.6) ...
Updating PPD files for cups-filters ...
Updating PPD files for foomatic-db-compressed-ppds ...
Updating PPD files for openprinting-ppds ...
Updating PPD files for c2esp ...
Updating PPD files for foo2zjs-common ...
Updating PPD files for gutenprint ...
Updating PPD files for hpcups ...
Updating PPD files for m2300w ...
Updating PPD files for postscript-hp ...
Updating PPD files for ptouch ...
Updating PPD files for pxljr ...
Updating PPD files for sag-gdi ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) ...
Processing triggers for dbus (1.12.2-1ubuntu1.1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Setting up ssh-import-id (5.7-0ubuntu1) ...

After that my Firefox was deleted despite the fact that it was running during the above operation. Well, I saw that some packages were going to be deleted but couldn't even imagine that Firefox was among them.

So the questions:

  1. Why command named install was about to delete something?
  2. Why apt-get decided that Firefox is no longer needed?
  3. How to use apt-get so that it doesn't automatically delete the applications and packages that I need and don't want to delete?
  4. Where can I read about the topics connected to this issue?

UPD

Firefox was deleted. It was still working but after I closed it I couldn't start it again as it was no longer present in my applications. Then I reinstalled it (via Ubuntu Software application) and needed to adjust it from scratch as nothing of my previous settings preserved.

As asked in the comments:

$ apt-cache policy firefox
firefox:
  Installed: (none)
  Candidate: 59.0.2+build1-0ubuntu1
  Version table:
     68.0.1+build1-0ubuntu0.18.04.1 -1
        100 /var/lib/dpkg/status
     59.0.2+build1-0ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

Oh, no! Seems VI was also removed:

$ sudo vi /etc/apt/sources.list
sudo: vi: command not found
$ which vi
<nothing>

It worked before the discussed operation.

Possible duplicate

Suggested possible duplicate How do I restore the default repositories? doesn't answers the questions asked here. But it helped eliminate the root cause of the discussed problem. After enabling "Important security updates" and "Recommended updated" in tab "Updates" package installation problems ceased.

Conclusion

mook765 completely answered the question.

Best Answer

Before you install a package with apt or apt-get you should make sure that the package cache is up to date and the system is upgraded.

sudo apt update    
sudo apt upgrade
sudo apt install <package-name>

apt manages deb-packages and the dependencies of the packages. That means if you install a package that depends on other packages, apt will handle that and install also the dependecies.

Some packages can not coexist (be installed) in the system at the same time, they conflict with each other. apt will also handle this situation, if you install package1 but package1 conflicts with package2 which is installed in your system, apt will remove package2 to make it possible to install package1.

This is going to be pretty complex if it comes to dependencies, if a dependency of an installed package is going to be removed, the dependent package is going to be removed too. Due to version conflicts this can happen easily if the system and the package-cache are not up to date or you added third party repositories (PPA's) to /etc/sources.list or /etc/sources.list.d/.

apt will always tell you what's going to happen, so in your case, you just need to read carefully:

The following packages will be REMOVED:
  brltty firefox gdb ...

and you have the chance to abort the operation by typing N and hitting Enter. So please, take the time and read command output carefully, you lose more time for troubleshooting if something goes wrong.

When I install install ssh-import-id on my system (18.04.3), it doesn't remove packages:

~$ sudo apt install ssh-import-id
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ncurses-term openssh-server openssh-sftp-server
Suggested packages:
  molly-guard monkeysphere rssh ssh-askpass
The following NEW packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 637 kB of archives.
After this operation, 5,316 kB of additional disk space will be used.
Do you want to continue? [Y/n] n
Abort.

So you have either a system which is not up to date or made changes to the repositories, we can't see that from the output you provided.

The packages apt told you that they are not longer needed and you should remove them with sudo apt autoremove are a leftover from a previous action, you removed other packages from your system before and some packages were left over.

Update:

As you provided the full command output recently, I'd recommend that you reinstall the 36 packages which have been removed before you do anything else, there are essential packages among them and you might end up with a broken system if you shutdown before reinstalling them.

Related Question