Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I currently use Xubuntu and was considering installing/trying GNOME Shell or Cinnamon by installing their respective metapackage. However, doing so would result in a massive number of dependencies being installed which would be almost impossible to remove individually at a later date if I decided I didn't like it. I wonder, therefore, if there is a way that I can track which packages Synaptic automatically downloads as part of the process and create a script of some sort to remove them all as well. I could then rest assured that if I don't like any of my new desktop environments, I can remove them in full without leaving a load of other applications and libraries lying around.

Thankyou for any help! :)

share|improve this question
add comment

3 Answers 3

You can use apt history log :

gedit /var/log/apt/history.log

and find on the log, the entry when you first installed the metapackage of your desktop env (Gnome-shell, Cinnamon, KDE...). You will find an entry like : apt-get install yourdesktopenv followed by all packages dependencies and their arch info.

Copy the whole entry and pase it in LibreOffice Writer, then use a Search/Replace using a regular expression : :amd64 \([0-9\~\.\+a-zA-Z\-, ]*\),? Replace by an empty space. (amd64 or i368 depending on your system arch) This replace operation will replace all the somedependency:amd64 (4.9.2-0ubuntu2, automatic), by somepackage . At the end, append sudo apt-get remove --auto-remove to the top of the replaced text. Copy and paste on Terminal.

Warning: this method is correct only if you have not performed significative updates between the time you first installed the desktop env and the time you want to remove it.


Ideally, you can automate these operations in a bash script:

 #!/bin/bash

#This creepy & very small script extracts package strings from APT history log file.
#Tested in Ubuntu 12.10 Linux
#this script is not fully portable; ksh & zsh not supported.
#---------------------------------------------------------------------------------------
#@author= hanynowsky@gmail.com
#---------------------------------------------------------------------------------------
#Beware. This scripts supposes you installed the desktop environment only once. Besides if 
#you performed significant updates from the time when you installed it and the time when
# you want to remove it, there is a risk that you'd likely remove other dependency packages needed by other programs. 
#---------------------------------------------------------------------------------------
#REGEXMATCH=`grep -Po ':amd64 \([0-9\~\.\+a-zA-Z\-, ]*\),?'`
#APPENDCOM=`sed -i '1isudo apt-get remove --auto-remove ' ~/Desktop/removeENV.txt`
# or sed 's/\[[^]]*\]//g'    instead of perl -lpwe   | tee ~/Desktop/removeENV.txt`
# insert command: sed '/Install:/ i\sudo apt-get remove --auto-remove '
# ARCH=`dpkg --print-architecture`   ->  variable to get arch (amd64 or i386)
#---------------------------------------------------------------------------------------

# k = kde | g = gnome-shell | c = cinnamon | x = xcfe | l = lmde | o = openbox
echo "Uninstall Desktop-Environment : "
read -p "Enter letter ( k ) for KUBUNTU - ( g ) for GNOME-SHELL - ( x ) for XUBUNTU - ( l ) for LUBUNTU - ( o ) for openbox : " desk
if [ "$desk" = "k" ]; then DESKSTRING="kubuntu-desktop"
elif [ "$desk" = "g" ]; then DESKSTRING="gnome-shell";
elif [ "$desk" = "x" ]; then DESKSTRING="xubuntu-desktop";
elif [ "$desk" = "l" ]; then DESKSTRING="lubuntu-desktop";
elif [ "$desk" = "o" ]; then DESKSTRING="openbox";
else DESKSTRING="UNKNOWN-DESKTOP-ENV"; echo "Sorry $USER, operation is not valid for $DESKSTRING" ; echo "Aborted."; exit 0;
fi

ARCH=`dpkg --print-architecture`
APTLOGFILE="/var/log/apt/history.log"
WARNING="This will uninstall your desktop environment : $DESKSTRING . Enter 'y' to continue, or 'n' to abort. "
read -p "$WARNING" option
if [ "$option" = "y" ]; then FETCHCOM=`sed -n "/$DESKSTRING/{:a;n;/End-Date/q;p;ba}" $APTLOGFILE | 
sed -e 's/Install://g'  | 
sed -e 's/,//g' | 
perl -lpwe "s/:$ARCH \(.*?\)//g" | tee ~/Desktop/un_desk_log.txt`
else FETCHCOM="aborted by $USER"
fi
if [ "$option" = "y" ]; then ACTIONCOM="sudo apt-get remove --auto-remove "
else ACTIONCOM=""
fi
FINALCOM=$ACTIONCOM$FETCHCOM
COMLOGFILE=~/Desktop/un_desk_log.txt
eval $FINALCOM | tee -a $COMLOGFILE
sed -i.bak '1i sudo apt-get remove --auto-remove ' $COMLOGFILE
exit 0;

Download the script here: http://ubuntuone.com/4CPFXpA2gFDRZtfS6Y7sva

share|improve this answer
1  
Fascinating script - I'm almost tempted to install a new DE just to test it out! :) Thankyou very much for taking the time to find/write (as applicable) this ;) –  Sman789 Oct 26 '12 at 20:23
    
You're welcome. PS: There was a small typo in the script that I've corrected and now it's working. Nevertheless, you it's subject to enhancements. So feel free to tweak it to your needs ;) –  Hanynowsky Oct 28 '12 at 1:15
add comment

This link may help you: http://www.psychocats.net/ubuntu/purexubuntu

I've used his method before and it's worked for me. He offers the option to return to a "Pure" Ubuntu, Kubuntu, Xubuntu or Lubuntu.

share|improve this answer
    
Thanks for this - but I'm more generally after something which will remove packages installed within, say, a certain time range. This way I can be sure that it won't remove anything I'd already installed previously, and that it will work for other environments than those listed there. Especially as I don't plan on actually installing the full system packages, just 'gnome-shell' or 'cinnamon' etc. –  Sman789 Oct 21 '12 at 0:57
add comment
up vote 0 down vote accepted

I found my own solution to this, and I'm kicking myself because it should have been obvious all along.

Install your program from the terminal, and simply copy/paste the list of dependencies it suggests into a text file. They're already in the perfect format for re-entry/pasting into the terminal at a later date (if you want to remove them).

For example:

sudo apt-get install unity

presents me with:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  lib32stdc++6 libdmx1
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  account-plugin-flickr appmenu-gtk appmenu-gtk3 appmenu-qt bamfdaemon compiz
  compiz-gnome geoclue geoclue-ubuntu-geoip gir1.2-accounts-1.0
  gir1.2-gdata-0.0 gir1.2-goa-1.0 gir1.2-signon-1.0 gir1.2-ubuntuoneui-3.0
  indicator-appmenu indicator-datetime indicator-printers libbamf3-0
  libdbusmenu-qt2 libglewmx1.8 libgnome-menu2 libnux-3.0-0 libnux-3.0-common
  libpackagekit-glib2-14 libsyncdaemon-1.0-1 libtimezonemap1
  libubuntuoneui-3.0-1 libunity-core-6.0-5 libunity-misc4 libunity-webapps0
  nux-tools python3-crypto python3-httplib2 python3-oauthlib
  rhythmbox-ubuntuone unity-asset-pool unity-common unity-lens-applications
  unity-lens-files unity-lens-music unity-lens-photos unity-lens-shopping
  unity-lens-video unity-scope-gdocs unity-scope-musicstores
  unity-scope-video-remote unity-services unity-webapps-service
Suggested packages:
  python3-crypto-dbg python-crypto-doc
The following NEW packages will be installed
  account-plugin-flickr appmenu-gtk appmenu-gtk3 appmenu-qt bamfdaemon compiz
  compiz-gnome geoclue geoclue-ubuntu-geoip gir1.2-accounts-1.0
  gir1.2-gdata-0.0 gir1.2-goa-1.0 gir1.2-signon-1.0 gir1.2-ubuntuoneui-3.0
  indicator-appmenu indicator-datetime indicator-printers libbamf3-0
  libdbusmenu-qt2 libglewmx1.8 libgnome-menu2 libnux-3.0-0 libnux-3.0-common
  libpackagekit-glib2-14 libsyncdaemon-1.0-1 libtimezonemap1
  libubuntuoneui-3.0-1 libunity-core-6.0-5 libunity-misc4 libunity-webapps0
  nux-tools python3-crypto python3-httplib2 python3-oauthlib
  rhythmbox-ubuntuone unity unity-asset-pool unity-common
  unity-lens-applications unity-lens-files unity-lens-music unity-lens-photos
  unity-lens-shopping unity-lens-video unity-scope-gdocs
  unity-scope-musicstores unity-scope-video-remote unity-services
  unity-webapps-service
0 upgraded, 49 newly installed, 0 to remove and 6 not upgraded.
Need to get 6,194 kB of archives.
After this operation, 23.8 MB of additional disk space will be used.
Do you want to continue [Y/n]? 

I simply copy and paste the list underneath The following NEW packages will be installed into a text file. Then I just replace the 'new line's with a space and it's all ready to paste back into sudo apt-get remove when I need it.

So to remove Unity (for me), the command is:

sudo apt-get remove account-plugin-flickr appmenu-gtk appmenu-gtk3 appmenu-qt bamfdaemon compiz compiz-gnome geoclue geoclue-ubuntu-geoip gir1.2-accounts-1.0 gir1.2-gdata-0.0 gir1.2-goa-1.0 gir1.2-signon-1.0 gir1.2-ubuntuoneui-3.0 indicator-appmenu indicator-datetime indicator-printers libbamf3-0 libdbusmenu-qt2 libglewmx1.8 libgnome-menu2 libnux-3.0-0 libnux-3.0-common libpackagekit-glib2-14 libsyncdaemon-1.0-1 libtimezonemap1 libubuntuoneui-3.0-1 libunity-core-6.0-5 libunity-misc4 libunity-webapps0 nux-tools python3-crypto python3-httplib2 python3-oauthlib rhythmbox-ubuntuone unity unity-asset-pool unity-common unity-lens-applications unity-lens-files unity-lens-music unity-lens-photos unity-lens-shopping unity-lens-video unity-scope-gdocs unity-scope-musicstores unity-scope-video-remote unity-services unity-webapps-service

Easy! And works for any program.

share|improve this answer
    
And what if you already installed and didn't copy the dependencies to a text file? How do you get them now? –  Parto Mar 11 at 13:55
    
Then nothing even remotely like my solution would be useful to you. Even if you could somehow access a log from when you originally installed the packages, it's likely that you've installed other things since then which share some of those dependancies (and therefore they would all be removed when you 'undid' the original installation). You might want to ask a seperate question. –  Sman789 Apr 29 at 2:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.