Remove Packages and Clean the System with apt-get
In this step, you will learn how to remove packages and clean up your system using the apt-get
command.
First, let's remove the tree
package that we installed in the previous step:
sudo apt-get remove tree
Example output:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
tree
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 152 kB of disk space will be freed.
Do you want to continue? [Y/n] Y
In the example above, we used the remove
operation to uninstall the tree
package.
Next, let's clean up the downloaded package files to free up disk space:
sudo apt-get clean
Example output:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The clean
operation removes the downloaded package files from the local repository, freeing up disk space on your system.
Finally, let's remove any packages that are no longer needed, using the autoremove
operation:
sudo apt-get autoremove
Example output:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
linux-headers-5.15.0-46 linux-headers-5.15.0-46-generic linux-image-5.15.0-46-generic
linux-modules-5.15.0-46-generic linux-modules-extra-5.15.0-46-generic
0 upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
After this operation, 321 MB of disk space will be freed.
Do you want to continue? [Y/n] Y
The autoremove
operation identifies and removes any packages that were installed automatically as dependencies and are no longer needed.