Introduction
Are you in the same situation as me, running out of space on your Virtual Server? Here are some tips on how to clean it up!
My server is running Debian 11, but these tips should work on other Linux distributions.
Yes, I had 0 free bytes on my server, that's why I wrote this article 😅
Simple method
Clean up temporary files and unnecessary packages:
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove
If you're already in root mode, you can remove the sudo
in front of the commands of course.
Delete files in /usr/local/share/.cache/
Is it risky?
No problem! You can delete files in cache folders such as /usr/local/share/.cache/yarn
or /usr/local/share/.cache
without any problem. These folders just contain temporary files used to improve performance, and they will be recreated automatically if a program needs them.
For more details on system caches and their management, see the official Debian documentation.
Cleaning procedure
1. Check the amount of space occupied by the cache Before deleting anything, make sure it's all there.
Before deleting anything, check how much space these files take up:
sudo du -sh /usr/local/share/.cache
2. Delete the contents of the cache
- To delete the Yarn cache only :
sudo rm -rf /usr/local/share/.cache/yarn
- To delete the entire contents of the
/usr/local/share/.cache
folder:
sudo rm -rf /usr/local/share/.cache/*
3. Check permissions
If you're working on a shared or multi-user server, make sure these folders aren't being used by other services or users before you empty them.
To understand permissions on Debian, consult the Linux permissions documentation.
Specifically clean Yarn
If you just want to take care of Yarn's cache, use the built-in command :
yarn cache clean
This will clean only what's unnecessary in the Yarn cache, leaving the rest untouched.
For more information, please consult the official Yarn documentation.
Important points to remember
- Deleted files will be recreated automatically if a program needs them, but this may slightly slow down the first use after cleaning.
- Always back up critical data before performing operations of this type, especially if you're on a large server.
- To monitor and better understand where your disk space is being used, you can use :
sudo du -ah /usr/local/share/.cache | sort -rh | head -n 20
This will give you a clear view of the largest files/folders.
For an even more detailed analysis, take a look at tools such as ncdu, a disk usage viewer in terminal mode.
Additional tip
If you want to automate cleaning, you can create a script or cron job that regularly empties these caches. For example, to clear the cache once a week:
- Open the cron editor:
bash crontab -e
` - Add this line:
bash 0 3 * * 0 sudo rm -rf /usr/local/share/.cache/*
This will run the cleanup every Sunday at 3am.
To learn more about automation with cron
, check out this guide to cron.
Top comments (2)
also don't forget docker! On my dev machine I had so much used storage that the docker daemon didnt start anymore and I couldnt run
docker system prune
lmaoNice tips!