安装软件包和依赖项并全部删除

安装软件包和依赖项并全部删除

我目前使用 Xubuntu,并考虑通过安装各自的元包来安装/尝试 GNOME Shell 或 Cinnamon。但是,这样做会导致安装大量依赖项,如果我不喜欢这些依赖项,几乎不可能在以后单独删除它们。因此,我想知道是否有办法跟踪 Synaptic 在此过程中自动下载的软件包,并创建某种脚本来删除它们。这样我就可以放心了,如果我不喜欢任何新的桌面环境,我可以完全删除它们,而不会留下大量其他应用程序和库。

感谢您的任何帮助! :)

答案1

您可以使用 apt 历史记录:

gedit /var/log/apt/history.log

并在日志中找到您首次安装桌面环境元包(Gnome-shell、Cinnamon、KDE...)时的条目。您将找到类似 : 的条目,apt-get install yourdesktopenv 后面是所有软件包依赖项及其 arch 信息。

复制整个条目并将其粘贴到 LibreOffice Writer 中,然后使用正则表达式进行搜索/替换::amd64 \([0-9\~\.\+a-zA-Z\-, ]*\),? 替换为空的空间。 (amd64 或 i368 取决于您的系统架构)此替换操作将替换所有 somedependency:amd64 (4.9.2-0ubuntu2, 自动),用 somepackage 。最后,附加sudo apt-get remove --auto-remove到替换文本的顶部。复制并粘贴到终端上。

警告:仅当您在第一次安装桌面环境和想要删除它之间没有执行重大更新时,此方法才正确。


理想情况下,你可以在 Bash 脚本中自动执行这些操作:

 #!/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= [email protected]
#---------------------------------------------------------------------------------------
#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;

在此处下载脚本:http://ubuntuone.com/4CPFXpA2gFDRZtfS6Y7sva

答案2

这个链接也许能帮到你:http://www.psychocats.net/ubuntu/purexubuntu

我以前用过他的方法,效果很好。他提供了返回“纯”Ubuntu、Kubuntu、Xubuntu 或 Lubuntu 的选项。

答案3

我找到了自己的解决方案,并且我很自责,因为这本来就应该是显而易见的。

从终端安装程序,然后只需将其建议的依赖项列表复制/粘贴到文本文件中即可。它们已经是完美的格式,可以在以后重新输入/粘贴到终端中(如果您想删除它们)。

例如:

sudo apt-get install unity

向我呈现:

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]? 

我只需将下面的列表复制并粘贴The following NEW packages will be installed到文本文件中即可。然后,我只需将“新行”替换为空格,sudo apt-get remove当我需要时,所有内容都可以粘贴回去。

因此,要删除 Unity(对我来说),命令是:

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

简单!并且适用于任何程序。

相关内容