Published | 17/12/2023 |
---|---|
Last Updated | 21/11/2024 |
Recently I need to downsize a DigitalOcean droplet to save cost. However the server used disk is much higher than I thought and I need to clean it up before snapshotting it.
Turn out there are more to consider that just few basic rm
commands to identify and remove unused files/directories. This articles briefly summarizes several ways to clean up an Ubuntu server.
apt-get autoremove
When we use program version managers, e.g. rvm
to manage ruby versions, nvm
to manage node versions, we may have multiple software versions installed along with their libraries. This often happens when we upgrade application, e.g. upgrading Rails app to a newer Ruby version. Ensure that we remove the unused versions to save space. In some cases their libraries are cached by other programs (e.g. Capistrano caches Ruby gems) and we need to ensure those are removed as well.
Lots of programs use cache to improve their performance and those caches may not be removed automatically. Ensure to check cache directories (they're often in ~/.cache
) and remove unnecessary ones.
du
commandsudo du / -h --max-depth=1
ncdu
is a command line TUI that allows us to analyze diskspace used by the server with a friendly UI to browse files and directories.
To install ncdu
sudo apt-get install ncdu
To analyze a directory
ncdu /path/to/directory