- Remove completely all packages I installed?
- 3 Answers 3
- Package management with APT
- Introduction
- Commands
- Installation commands
- auto-apt
- Maintenance commands
- Removal commands
- Search commands
- Typical usage example
- Setting up apt-get to use a http-proxy
- Temporary proxy session
- APT configuration file method
- BASH rc method
- How to login a proxy user
- Useful additional packages
- Additional links
- Troubleshooting
- How can I uninstall all the packages I’ve installed today?
- 3 Answers 3
- For apt packages
- For snap packages
Remove completely all packages I installed?
I was using one Linux server with CentOS7 installed for testing and installing some tools. And now I don’t remember how many packages I installed. I want to remove all that packages so my server would be like new as it was. I don’t want to search for every package and remove one by one. Is there any way to remove them with just only one command?
/var/log/yum.log might be helpful, it lists both the package name and a timestamp. As far as I can see, it doesn’t list packages added by the initial installs.
The yum.log file would list all packages I installed, but how could i delete all of them with only 1 command?
«Standard shell techniques» 😉 like sudo yum remove $(gawk ‘$0 ~ /Installed/
3 Answers 3
List all the files in the reverse order of their installation date into a file:
atop-2.1-1.fc22.x86_64 Wed Apr 13 07:35:27 2016 telnet-server-0.17-60.fc22.x86_64 Mon Apr 11 20:10:43 2016 mhddfs-0.1.39-3.fc22.x86_64 Sat Apr 9 21:26:06 2016 libpcap-devel-1.7.3-1.fc22.x86_64 Fri Apr 8 09:40:43 2016
Choose the cutoff date that applies to you and delete all the lines that follow it. Give the remaining lines to yum to remove, after removing the date part. Eg
You can also try with yum history and usually you get a numbered list of what has been installed, like :
[root@localhost ~]# yum history Loaded plugins: product-id, refresh-packagekit, subscription-manager Updating Red Hat repositories. ID | Login user | Date and time | Action(s) | Altered 3 | root | 2011-09-14 14:36 | Install | 1 2 | root | 2011-09-12 15:48 | I, U | 80 1 | System | 2011-09-12 14:57 | Install | 1025
and you can use afterwards yum history undo 3 for example.
More details about yum history here.
Package management with APT
Package management via apt-get runs hand-in-hand with the /etc/apt/sources.list file. For information on editing or updating your sources list see SourcesList.
Introduction
This page describes how to handle the packages on your system using apt-get and related commands. For example, you can install a new package, remove an installed package, or update all installed packages to the latest versions.
Commands
- Example:
sudo apt-get install ubuntu-desktop
Installation commands
Use the -s flag to simulate an action. For example: «apt-get -s install » will simulate installing the package, showing you what packages will be installed and configured. |
auto-apt
This command runs
Maintenance commands
The same as the above, except add the «smart upgrade» checkbox. It tells APT to use «smart» conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary.
«apt-get dist-upgrade» does not upgrade from a previous version of Ubuntu. For more information of upgrading from a previous version of Ubuntu see http://www.ubuntu.com/getubuntu/upgrading . |
du -sh /var/cache/apt/archives
Reconfigure the named package. With many packages, you’ll be prompted with some configuration questions you may not have known were there.
- For example:
dpkg-reconfigure fontconfig-config
echo " hold" | dpkg --set-selections
This command may have the unintended side effect of preventing upgrades to packages that depend on updated versions of the pinned package. apt-get dist-upgrade will override this, but will warn you first. If you want to use this command with sudo, you need to use echo " hold" | sudo dpkg --set-selections not sudo echo " hold" | dpkg --set-selections. |
echo " install" | dpkg --set-selections
Removal commands
This command completely removes a package and the associated configuration files. Configuration files residing in ~ are not usually affected by this command.
- + operator
- If you want to remove package1 and install package2 in one step:
dpkg -l | grep '^rc' | awk '' | xargs dpkg --purge
Search commands
This command determines which installed package owns
. It shows files from installed packages that match , with the name of the package they came from. Consider this to be a «reverse lookup» utility. In order to use this command, the package dlocate must be installed on your system. dpkg -L package | grep /usr/bin
For more information on apt-get, apt-cache and dpkg consult their manual pages by using the man command. These manuals will provide a wider scope of information in addition to all of the options that you can use with each program.
- Example:
Typical usage example
I want to feel the wind in my hair, I want the adrenaline of speed. So let’s install a racing game. But what racing games are available?
apt-cache search racing game
It gives me a lot of answers. I see a game named «torcs». Let’s get some more information on this game.
Hmmm. it seems interesting. But is this game not already installed on my computer? And what is the available version? Which repository is it from (Universe or Main)?
Ok, so now, let’s install it!
What is the command I must type in the console to launch this game? In this example, it’s straightforward («torcs»), but that’s not always the case. One way of finding the name of the binary is to look at what files the package has installed in «/usr/bin». For games, the binary will be in «/usr/games». For administrative programs, it’s in «/usr/sbin».
dpkg -L torcs | grep /usr/games/
The first part of the command display all files installed by the package «torcs» (try it). With the second part, we ask to only display lines containing «/usr/games/».
Hmmm, that game is cool. Maybe there are some extra tracks?
But I’m running out of space. I will delete the apt cache!
Oh no, my mother asked me to remove all games from this computer. But I want to keep the configuration files so I can simply re-install it later.
If I want to also remove config files :
Setting up apt-get to use a http-proxy
These are three methods of using apt-get with a http-proxy.
Temporary proxy session
This is a temporary method that you can manually use each time you want to use apt-get through a http-proxy. This method is useful if you only want to temporarily use a http-proxy.
Enter this line in the terminal prior to using apt-get (substitute your details for yourproxyaddress and proxyport).
export http_proxy=http://yourproxyaddress:proxyport
If you normally use sudo to run apt-get you will need to login as root first for this to work unless you also add some explicit environment settings to /etc/sudoers, e.g.
Defaults env_keep = "http_proxy https_proxy ftp_proxy"
APT configuration file method
This method uses the apt.conf file which is found in your /etc/apt/ directory. This method is useful if you only want apt-get (and not other applications) to use a http-proxy permanently.
gksudo gedit /etc/apt/apt.conf
Add this line to your /etc/apt/apt.conf file (substitute your details for yourproxyaddress and proxyport).
Acquire::http::Proxy "http://yourproxyaddress:proxyport";
BASH rc method
This method adds a two lines to your .bashrc file in your $HOME directory. This method is useful if you would like apt-get and other applications for instance wget, to use a http-proxy.
Add these lines to the bottom of your ~/.bashrc file (substitute your details for yourproxyaddress and proxyport)
http_proxy=http://yourproxyaddress:proxyport export http_proxy
Save the file. Close your terminal window and then open another terminal window or source the ~/.bashrc file:
Test your proxy with sudo apt-get update and whatever networking tool you desire. You can use firestarter or conky to see active connections.
If you make a mistake and go back to edit the file again, you can close the terminal and reopen it or you can source ~/.bashrc as shown above.
How to login a proxy user
If you need to login to the Proxy server this can be achieved in most cases by using the following layout in specifying the proxy address in http-proxy. (substitute your details for username, password, yourproxyaddress and proxyport)
http_proxy=http://username:password@yourproxyaddress:proxyport
Useful additional packages
Additional links
Troubleshooting
How can I uninstall all the packages I’ve installed today?
I was trying to get musepack encoder support built into ffmpeg today, and I inadvertently broke a few things but I’m not sure exactly which package I installed which broke them. How can I remove ALL packages I installed today, and start again from scratch more carefully? I can see a list of them in «Ubuntu Software Center» under today’s date in the «History», but I don’t want to go through uninstalling them one-by-one, because there are hundreds to do.
3 Answers 3
grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk '/install / ' | uniq | xargs apt-get -y remove
found on commandlinefu worked fine for me
I just tested the grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk ‘/install /
‘ | uniq output, was exactly the packages I installed using apt-get today!! nice script buddy, +1. E: Could not open lock file /var/lib/dpkg/lock-frontend — open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root? even with sudo
The file /var/log/apt/history.log has what you need. Take a look at the answer: How to reinstall many removed packages at once? it’s a more detailed answer.
Disclaimer: Nala is still in a development stage, and is not recommended for any professional use.
For apt packages
If you’re ready to use the command line to install new packages, it’s possible to get an easy undo feature with the more modern apt front-end called nala (for 22.04 you have to enable the «universe» repository). Note: This will only work for apt / .deb packages.
From this point, use nala to install new packages on your system, using:
Leave security updates etc. to the unattended-upgrades package.
Now, when you run the command nala history , you get a list of the commands run with nala, including installed packages. To filter only new installations, use:
nala history | grep install
An added bonus of the history feature is that you can undo any step in the history, so that you can easily reverse package installation procedures. This can be done by issuing the command:
Where is the ID number of the transaction in the history list you want to undo.
For snap packages
Snap has its own «undo» feature, where you can easily revert to the previously installed version. This is done with:
In case you want to revert to a specific revision of a snap package, this can be stated as well;
sudo snap revert --revision