Ubuntu – How to completely remove php libraries

aptaptitudePHPuninstallzsh

I use zsh. when I try to upgrade the system, some packages related to php pop up, I want to remove them

$ sudo apt-get upgrade              
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  fonts-opensymbol kdelibs-bin kdelibs5-data kdelibs5-plugins kdoctools
  libkcmutils4 libkde3support4 libkdeclarative5 libkdecore5 libkdesu5
  libkdeui5 libkdewebkit5 libkdnssd4 libkemoticons4 libkfile4 libkhtml5
  libkidletime4 libkio5 libkjsapi4 libkjsembed4 libkmediaplayer4
  libknewstuff3-4 libknotifyconfig4 libkntlm4 libkparts4 libkprintutils4
  libkpty4 libkrosscore4 libktexteditor4 libnepomuk4 libnepomukquery4a
  libnepomukutils4 libplasma3 libsolid4 libssl1.0.0 libssl1.0.0:i386
  libthreadweaver4 openssl php-pear php5-cli php5-common php5-curl php5-fpm
  php5-gd php5-intl php5-mysql php5-pspell php5-readline php5-recode php5-snmp
  php5-sqlite php5-tidy php5-xmlrpc php5-xsl
54 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 18.4 MB/20.0 MB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 

What I tried:

 sudo apt-get remove php
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package php

▶ sudo apt-get remove php*
zsh: no matches found: php*

sudo apt-get remove php *
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'dropbox' is not installed, so not removed
E: Unable to locate package php
E: Unable to locate package avlfolder
E: Unable to locate package boot-scripts
E: Unable to locate package Calibre Library
E: Unable to locate package Desktop
E: Unable to locate package Documents
E: Unable to locate package Downloads
E: Unable to locate package Dungeons and Dragons Online
E: Unable to locate package Games
E: Unable to locate package java ide
E: Unable to locate package jdownloader
E: Unable to locate package lello
E: Unable to locate package liberam
E: Unable to locate package Music
E: Unable to locate package netbeans-8.0
E: Couldn't find any package by regex 'netbeans-8.0'
E: Unable to locate package netbeans-8.0.desktop
E: Couldn't find any package by regex 'netbeans-8.0.desktop'
E: Unable to locate package Pictures
E: Unable to locate package PlayOnLinux's virtual drives
E: Unable to locate package projects
E: Unable to locate package Public
E: Unable to locate package qtprojects
E: Unable to locate package Savage2
E: Unable to locate package sketchbook
E: Unable to locate package Templates
E: Unable to locate package text.txt
E: Couldn't find any package by regex 'text.txt'
E: Unable to locate package themes
E: Unable to locate package tor-browser-linux64-3.6.1_en-US.tar.xz
E: Couldn't find any package by regex 'tor-browser-linux64-3.6.1_en-US.tar.xz'
E: Unable to locate package Videos
E: Unable to locate package VirtualBox VMs
E: Unable to locate package workspace
E: Unable to locate package xal

And I tried the same with php5 and with purge, nothing has changed. autoremove didn't work either

Update

Since I had no answer so far, I ran

sudo apt-get remove --purge php-pear php5-cli php5-common php5-curl php5-fpmphp5-gd php5-intl php5-mysql php5-pspell php5-readline php5-recode php5-snmpphp5-sqlite php5-tidy php5-xmlrpc php5-xsl
[sudo] password for elie: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package php5-fpmphp5-gd
E: Unable to locate package php5-snmpphp5-sqlite

I was looking for a better solution, anyway I don't understand how php5-fpmphp5-gd and php5-snmpphp5-sqlite need to be upgraded if they aren't installed. How could the system detect that they need to be upgraded, but didn't detect them when I tried to remove them?

Best Answer

zsh, unlike bash, has a different glob/wildcard/expansion system, so it works differently so php*might not work as you expect.
So are instead of sudo apt-get remove php*, you could:

  • Quote it:

    sudo apt-get remove "php*"
    
  • Bash it:

    bash -c "sudo apt-get remove php*"
    

N.B. Whilst also being a bad idea (as previously pointed out), sudo apt-get remove php * returned the names of files and foldersin the current working directory (likely your home directory) because of the * - but this also means if you have any files in hte terminal's current working directory beginning with php, you may have a problem using php* to request stuff, as it might include those filenames in the expansion.

Another N.B. php5-fpmphp5-gd and php5-snmpphp5-sqlite might of been part of the update, as some of the packages being updated needed those packages as new dependencies. By php5-fpmphp5-gd and php5-snmpphp5-sqlite, you probably meant php5-fpm, php5-gd, php5-snmp, php5-sqlite... (looking at the output you provided, it was because newlines occurred at those points) you probably should of ran:

sudo apt-get remove --purge php-pear php5-cli php5-common php5-curl php5-fpm php5-gd php5-intl php5-mysql php5-pspell php5-readline php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl