How to clean your dev junk and free disk space
Radomir Perišić
Posted on February 1, 2022
WARNING: All processes are irreversible!
Node.js
Delete all unused global node modules and Node.js executables installed with nvm
Running nvm ls
will show you all versions installed, you can use nvm uninstall v12.2.0
for example to uninstall a specific version, however this doesn't remove global npm packages that you installed for this version. It's better to go to ~/.nvm/versions/node
folder and rm -rf
versions that you don't need.
A useful command to delete all versions that you aren't currently using:
cd ~/.nvm/versions/node; ls -A | grep -v `nvm current` | xargs rm -rf
Delete all node_modules folders from your projects
Commands taken from this article
Check size of node_modules in folder with your projects
# Mac / Linux
cd documents
find . -name "node_modules" -type d -prune | xargs du -chs
# Windows
cd documents
FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" echo %d"
# --- Example output ---
255M ./someProject/node_modules
482M ./anotherOne/node_modules
707M total
Delete all node_modules folders
# Mac / Linux
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
# Windows
FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rm -rf "%d"
Yarn and npm cache
yarn cache clean
npm cache clean --force
Xcode
Really nice tool for deleting old simulators, archives and other Xcode junk: https://apps.apple.com/us/app/devcleaner-for-xcode/id1388020431?mt=12
Homebrew
Homebrew periodacaly performs cleanup but if you need some extra space now, you can run:
brew cleanup
Docker
Docker needs to be running for this to work.
Be aware that docker removes all images that currently aren't used, so if you want to keep something, start it and it won't be deleted. Check docs for more info.
docker system prune -a
# add '--volumes' to delete all volumes as well
If you have some lang/tool/ide that requires cleanup leave a comment and I will add it.
Posted on February 1, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.