Running `sudo apt purge python` leads to total system crash [duplicate]
Solution 1:
Why am I faced with a total crash of Ubuntu Focal Fossa 20.04 LTS, if I run the following command?
sudo apt purge python*
Python is a core component of Ubuntu and, as such, Ubuntu strongly depends on it. Removing it leads to a complete crash of the system, just as you witnessed. While there could be ways of fixing Ubuntu after breaking the installation of Python, the best option is to completely reinstall the system.
I don't receive any alert from
apt
about that action before I start that process!
I'm not sure that apt
didn't alert you of the removal of several packages. Running a simulation of purging python3
from my system (using apt
's -s
flag - see man apt
), returns the following:
$ apt -s purge python3
NOTE: This is only a simulation!
apt needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
apg apport-symptoms aptdaemon-data avahi-utils cups-pk-helper dc dconf-cli dctrl-tools distro-info distro-info-data docbook-xml evolution-data-server evolution-data-server-common fonts-cantarell fprintd
geoip-database gir1.2-accountsservice-1.0 gir1.2-atspi-2.0 gir1.2-clutter-1.0 gir1.2-clutter-gst-3.0 gir1.2-cogl-1.0 gir1.2-coglpango-1.0 gir1.2-dbusmenu-glib-0.4 gir1.2-dee-1.0 gir1.2-gck-1 gir1.2-gcr-3
gir1.2-gdm-1.0 gir1.2-geoclue-2.0 gir1.2-gnomebluetooth-1.0 gir1.2-goa-1.0 gir1.2-graphene-1.0 gir1.2-gtkclutter-1.0 gir1.2-gtksource-3.0 gir1.2-gweather-3.0 gir1.2-handy-0.0 gir1.2-ibus-1.0 gir1.2-json-1.0
gir1.2-keybinder-3.0 gir1.2-mutter-6 gir1.2-nm-1.0 gir1.2-nma-1.0 gir1.2-notify-0.7 gir1.2-packagekitglib-1.0 gir1.2-polkit-1.0 gir1.2-rsvg-2.0 gir1.2-secret-1 gir1.2-snapd-1 gir1.2-unity-5.0
gir1.2-upowerglib-1.0 gir1.2-vte-2.91 gkbd-capplet gnome-control-center-faces gnome-session-bin gnome-session-common gnome-shell-common gnome-startup-applications ibus-data ippusbxd libarchive-tools
libatomic1:i386 libboost-python1.71.0 libbsd0:i386 libcamel-1.2-62 libchromaprint-tools libcolord-gtk1 libdiscid0 libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386 libdrm-radeon1:i386 libdrm2:i386
libebackend-1.2-10 libebook-1.2-20 libebook-contacts-1.2-3 libecal-2.0-1 libedata-book-1.2-26 libedata-cal-2.0-1 libedataserver-1.2-24 libedataserverui-1.2-2 libedit2:i386 libelf1:i386 libetonyek-0.1-1
libexpat1:i386 libexpat1-dev libffi7:i386 libfluidsynth2 libfprint-2-2 libgdata-common libgdata22 libgeoip1 libgl1:i386 libgl1-mesa-dri:i386 libglapi-mesa:i386 libglvnd0:i386 libglx-mesa0:i386 libglx0:i386
libgnomekbd-common libgnomekbd8 libgsoap-2.8.91 libgssdp-1.2-0 libgupnp-1.2-0 libgupnp-av-1.0-2 libgupnp-dlna-2.0-3 libhpmud0 libimagequant0 libinstpatch-1.0-2 libjpeg-turbo-progs libjuh-java libjurt-java
libkeybinder-3.0-0 libldb2 libllvm12:i386 liblzf1 libmediaart-2.0-0 libmikmod3 libmodplug1 libmspub-0.1-1 libmtp-common libmtp-runtime libmtp9 libmutter-6-0 libmwaw-0.3-3 libnetplan0 libnfs13
libnvidia-cfg1-450-server libnvidia-common-450-server libnvidia-compute-450-server:i386 libnvidia-decode-450-server libnvidia-decode-450-server:i386 libnvidia-encode-450-server
libnvidia-encode-450-server:i386 libnvidia-extra-450-server libnvidia-fbc1-450-server libnvidia-fbc1-450-server:i386 libnvidia-gl-450-server libnvidia-gl-450-server:i386 libnvidia-ifr1-450-server
libnvidia-ifr1-450-server:i386 liborcus-0.15-0 libpam-fprintd libpciaccess0:i386 libphonenumber7 libportmidi0 libprotobuf17 libpython3-dev libpython3-stdlib libpython3.8-dev libqt5designer5 libqt5help5
libqt5multimedia5 libqt5multimedia5-plugins libqt5multimediagsttools5 libqt5multimediawidgets5 libqt5opengl5 libqt5sql5 libqt5sql5-sqlite libqt5test5 libqt5xml5 libreoffice-style-tango libridl-java
librygel-core-2.6-2 librygel-db-2.6-2 librygel-renderer-2.6-2 librygel-server-2.6-2 libsane-hpaio libsdl-image1.2 libsdl-mixer1.2 libsdl-ttf2.0-0 libsdl1.2debian libsensors5:i386 libstdc++6:i386 libtalloc2
libtevent0 libtorrent-rasterbar9 libunoil-java libutempter0 libva-wayland2 libvncserver1 libvte-2.91-0 libvte-2.91-common libvulkan1:i386 libwayland-client0:i386 libwbclient0 libwhoopsie-preferences0
libwps-0.4-4 libx11-6:i386 libx11-xcb1:i386 libxatracker2 libxau6:i386 libxcb-dri2-0:i386 libxcb-dri3-0:i386 libxcb-glx0:i386 libxcb-present0:i386 libxcb-randr0:i386 libxcb-res0 libxcb-shm0:i386
libxcb-sync1:i386 libxcb-xfixes0:i386 libxcb-xv0 libxcb1:i386 libxdmcp6:i386 libxext6:i386 libxfixes3:i386 libxfont2 libxklavier16 libxnvctrl0 libxshmfence1:i386 libxvmc1 libxxf86vm1:i386 libyelp0
linux-headers-5.4.0-26 linux-headers-5.4.0-26-generic linux-headers-5.8.0-63-generic linux-hwe-5.8-headers-5.8.0-63 mesa-vulkan-drivers:i386 mobile-broadband-provider-info mscompress mutter mutter-common
network-manager-gnome nvidia-compute-utils-450-server nvidia-kernel-common-450-server nvidia-kernel-source-450-server nvidia-utils-450-server plymouth-label policykit-1-gnome printer-driver-hpcups
python-apt-common python-pip-whl python3-minimal python3.8 python3.8-dev python3.8-minimal rygel sgml-base sgml-data switcheroo-control timgm6mb-soundfont whoopsie-preferences x11-session-utils x11-xkb-utils
xbrlapi xfonts-base xfonts-encodings xfonts-scalable xfonts-utils xinit xinput xml-core xserver-common xserver-xephyr xserver-xorg-core xserver-xorg-input-all xserver-xorg-input-libinput
xserver-xorg-input-wacom xserver-xorg-legacy xserver-xorg-video-all xserver-xorg-video-amdgpu xserver-xorg-video-ati xserver-xorg-video-fbdev xserver-xorg-video-intel xserver-xorg-video-nouveau
xserver-xorg-video-nvidia-450-server xserver-xorg-video-qxl xserver-xorg-video-radeon xserver-xorg-video-vesa xserver-xorg-video-vmware xterm xwayland yelp-xsl zlib1g-dev
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
policykit-1-gnome
The following packages will be REMOVED:
apparmor* apport* apport-gtk* aptdaemon* apturl* apturl-common* autokey-common* autokey-gtk* celluloid* chrome-gnome-shell* command-not-found* deluge* deluge-common* deluge-gtk* dkms* exfalso* firefox*
foomatic-db-compressed-ppds* gdm3* gnome-control-center* gnome-getting-started-docs* gnome-getting-started-docs-el* gnome-menus* gnome-online-accounts* gnome-session* gnome-shell*
gnome-shell-extension-appindicator* gnome-shell-extension-desktop-icons* gnome-shell-extension-prefs* gnome-shell-extension-ubuntu-dock* gnome-tweaks* gnome-user-docs* gnome-user-docs-el* gufw* gvfs-backends*
hplip* hplip-data* ibus* ibus-table* imgsizer* language-selector-common* language-selector-gnome* libmpv1* libsmbclient* lsb-release* mpv* nautilus-share* netplan.io* networkd-dispatcher*
nvidia-dkms-450-server* nvidia-driver-450-server* nvidia-prime* nvidia-settings* openprinting-ppds* orca* picard* plymouth-theme-spinner* plymouth-theme-ubuntu-text* printer-driver-foo2zjs*
printer-driver-foo2zjs-common* printer-driver-m2300w* printer-driver-postscript-hp* printer-driver-ptouch* printer-driver-pxljr* printer-driver-sag-gdi* python3* python3-appdirs* python3-apport* python3-apt*
python3-aptdaemon* python3-aptdaemon.gtk3widgets* python3-attr* python3-automat* python3-babelfish* python3-blinker* python3-brlapi* python3-bs4* python3-cairo* python3-certifi* python3-cffi-backend*
python3-chardet* python3-click* python3-colorama* python3-commandnotfound* python3-constantly* python3-cryptography* python3-cups* python3-cupshelpers* python3-dateutil* python3-dbus* python3-debconf*
python3-debian* python3-decorator* python3-defer* python3-dev* python3-distro* python3-distro-info* python3-distupgrade* python3-distutils* python3-dogpile.cache* python3-entrypoints* python3-enzyme*
python3-feedparser* python3-gdbm* python3-geoip* python3-gi* python3-gi-cairo* python3-greenlet* python3-guessit* python3-hamcrest* python3-html5lib* python3-httplib2* python3-hyperlink* python3-ibus-1.0*
python3-idna* python3-incremental* python3-jwt* python3-keyring* python3-launchpadlib* python3-lazr.restfulclient* python3-lazr.uri* python3-lib2to3* python3-libdiscid* python3-libtorrent* python3-louis*
python3-lxml* python3-macaroonbakery* python3-mako* python3-markupsafe* python3-msgpack* python3-musicbrainzngs* python3-mutagen* python3-nacl* python3-neovim* python3-netifaces* python3-numpy*
python3-oauthlib* python3-olefile* python3-openssl* python3-pbr* python3-pexpect* python3-pil* python3-pip* python3-pkg-resources* python3-problem-report* python3-protobuf* python3-ptyprocess* python3-pyasn1*
python3-pyasn1-modules* python3-pyatspi* python3-pygame* python3-pyinotify* python3-pymacaroons* python3-pynvim* python3-pyqt5* python3-pyqt5.qtmultimedia* python3-pysrt* python3-rarfile* python3-rebulk*
python3-rencode* python3-renderpm* python3-reportlab* python3-reportlab-accel* python3-requests* python3-requests-unixsocket* python3-rfc3339* python3-secretstorage* python3-service-identity*
python3-setproctitle* python3-setuptools* python3-simplejson* python3-sip* python3-six* python3-software-properties* python3-soupsieve* python3-speechd* python3-stevedore* python3-subliminal* python3-systemd*
python3-talloc* python3-toposort* python3-twisted* python3-twisted-bin* python3-tz* python3-uno* python3-update-manager* python3-urllib3* python3-wadllib* python3-webencodings* python3-wheel* python3-xdg*
python3-xkit* python3-xlib* python3-yaml* python3-zope.interface* quodlibet* ranger* samba-libs* screen-resolution-extra* snapd* software-properties-common* software-properties-gtk* subliminal*
system-config-printer* system-config-printer-common* system-config-printer-udev* ubuntu-advantage-tools* ubuntu-desktop* ubuntu-desktop-minimal* ubuntu-docs* ubuntu-drivers-common* ubuntu-minimal*
ubuntu-release-upgrader-core* ubuntu-release-upgrader-gtk* ubuntu-session* ubuntu-standard* ufw* unattended-upgrades* update-manager* update-manager-core* update-notifier* update-notifier-common* virtualbox*
virtualbox-dkms* virtualbox-qt* xorg* xserver-xorg* yelp*
Obviously these are a lot of packages that depend on python3
and are getting removed, and you can see many crucial ones among them. When you ran sudo apt purge python*
, I suppose that a similar output was shown to you before confirming the removal of the packages. So apt
not alerting you is not entirely true.
How can I avoid this precarious software problem and how can I be prepared in the future for cases like this?
-
Do not remove the default Python installation! If you need a Python version other than the one that comes preinstalled, I strongly advise you to use a virtual environment to install that. You can have a look at
venv
or the Anaconda Python distribution (which I personally use and recommend). -
If you don't have a strong reason, please don't mess with core components.
-
Before removing packages that you don't know about, you can run a simulation of the removal, without actually removing anything, using
apt
's-s
flag (as I did above). -
Have a backup of your important personal files and configs.
Solution 2:
Removing Python is removing a part of the operating system.
When you run the command sudo apt purge python*
, it comes with several responsibilities.
- You're running it as
sudo
, which means you should know what you're doing. - You're removing a default system package - again you should know the implications of this beforehand.
An analogy to this would be to delete the system32
folder in Windows (folder containing lots of system executables and libraries), and then complain the OS is not working afterwards.