Brief: Running out of space on your Linux system? Here are several ways you can clean up your system to free up space on Ubuntu and other Ubuntu based Linux distributions.
Over time, any operating system can become cluttered as programs are added and removed. If you have like a TB of storage capacity, you might not bother to clean up Ubuntu to make some disk space. But if your hard disk has limited space, like I have a 128 GB SSD laptop, freeing up disk space becomes a necessity.
In this article, I’ll show you some of the easiest tricks to clean up your Ubuntu system and get more space.
How to free up disk space in Ubuntu and Linux Mint
There are several ways you clean up disk space in Ubuntu and other Ubuntu based system. I have discussed several command line tricks here followed by some GUI options.
While I have mentioned several ways here, if you are a beginner, avoid the ones marked as ‘expert’. Not that you cannot use them, but it’s better to avoid if you don’t know what you are doing.
I am using Ubuntu 16.04 while writing this tutorial but you can use the same steps for other Ubuntu versions, Linux Mint, elementary OS and other Ubuntu based Linux distributions.
1. Get rid of packages that are no longer required
If you read the apt-get commands guide, you might have come across the apt-get command option ‘autoremove’.
This option removes libs and packages that were installed automatically to satisfy the dependencies of an installed package. If that package is removed, these automatically installed packages are useless in the system. This command automatically removes such packages.It also removes old Linux kernel that
It also removes old Linux kernels that were installed from automatically in the system upgrade.
It’s a no-brainer command that you can run from time to time to make some free space on your Ubuntu system:
sudo apt-get autoremove
As you can see, this command is going to free up 300 Mb of free space in my system.
2. Clean up APT cache in Ubuntu
Ubuntu uses APT (Advanced Package Tool) for installing, removing and managing software on the system, and in doing so it keeps a cache of previously downloaded and installed packages even after they’ve been uninstalled.
The APT package management system keeps a cache of DEB packages in /var/cache/apt/archives. Over time, this cache can grow quite large and hold a lot of packages you don’t need.
You can see the size of this cache with the command below:
sudo du -sh /var/cache/apt
As you can see, I have over 500 Mb of cache storage. When you are almost out of space, this 500 Mb can make a lot of difference.
Now, you have two options to handle the cache.
Either remove only the outdated packages, like those superseded by a recent update, making them completely unnecessary.
sudo apt-get autoclean
Or clean out the cache in its entirety (frees more disk space):
sudo apt-get clean
3. Clean the thumbnail cache
Ubuntu automatically creates a thumbnail, for viewing in the file manager. It stores those thumbnails in a hidden directory in your user account at the location ~/.cache/thumbnails.
Over time, the number of thumbnails would increase dramatically. Moreover, the thumbnail cache will eventually contain many superfluous thumbnails of pictures that don’t exist anymore.
You can check the size of thumbnail cache with the command below:
du -sh ~/.cache/thumbnails
For my system, the thumbnail cache is over 300 Mb in size.
So it’s a good practice to clear the thumbnail cache every few months or so. The quickest way is to use the terminal:
rm -rf ~/.cache/thumbnails/*
4. Remove old Linux kernels that were manually installed [Expert]
The command discussed in the point 1 removes old Linux kernel. But it won’t work if you manually installed the kernel in Ubuntu. But removing old, unused Linux kernels will still save you plenty of space.
So, if you manually installed a Linux kernel, perhaps you can manually uninstall it as well.
List all installed Linux kernels first:
sudo dpkg --list 'linux-image*'
Removing the old kernels is the same as removing any other package. I’m using shell expansion for the version numbers to save typing. It will prompt you with a list of packages that will be removed, so you can double check the list before continuing.
Note: Replace VERSION with the version of the kernel you want to remove
sudo apt-get remove linux-image-VERSION
My recommendation is to keep at least two or preferably three kernels including the latest. This way, you will have at least one/two other kernels to boot with, if for whatever reason the latest kernel you are unable to boot with.
5. Remove orphaned packages [Expert]
First, let’s see what is an orphaned package in Ubuntu.
Suppose you installed a package ‘myprogram’. But this package has a dependency on the library ‘mylib’. This lib will be usually installed automatically with ‘myprogram’. When you delete ‘myprogram’, mylib might still remain in the system. Thus mylib, in this case, becomes an orphaned package.
Now, the command listed in point 1 removes such orphaned packages. But imagine the case where you had manually installed mylib before installing myprogram. The command ‘apt autoremove’ might not remove the orphaned package in this case. And hence you’ll have to manually delete it.
You’ll have to find all the orphaned packages first and then remove them. Thankfully, we have a GUI tool to do that: gtkorphan, a graphical frontend for deborphan.
Install gtkorphan via the terminal:
sudo apt-get install gtkorphan
And to remove orphaned packages, search for Removed Orphaned Package tool and run it to find all the orphaned packages in your system:
Honestly, I won’t go for this option unless you really need every Mb of free space.
6. Uninstalling unnecessary applications
We all have a few games and/or applications that we hardly use. Don’t trust me? Go and find installed software in Ubuntu system.
Chances are that you have a number of apps installed that you seldom use. Maybe you installed them on the back of an awesome review, out of nosiness, or to handle a particular task.
If you need space more getting rid of the unused or lesser used applications is always a good idea.
You can remove a program from the software centre or using the command below with particular app name:
sudo apt-get remove package-name1 package-name2
7. Using GUI tools to free space in Ubuntu
We saw a number of command line options to make space in Linux system but I understand if you don’t want to use the commands.
Remembering all the commands or using them all one by one may not be convenient for you. And this is why we have a number of GUI tools that will help you do that in a few clicks with an easy to use interface.
Stacer is one such tool that you could use. You can read this article to know how to use Stacer in Ubuntu.
You can check out more tools to clean up Ubuntu and make some free space easily.
So, you saw a number of ways to clean up Ubuntu system. Personally, I use apt-get autoremove more often than any other commands here. Regularly using this command keeps the system free from unnecessary files.
I hope this article helped you to make free space in Ubuntu, Linux Mint and other such distributions. Do let me know if this worked for you or if you have some other tip to share.