DEV Community

Radomir Perišić
Radomir Perišić

Posted on • Edited on

How to clean your dev junk and free disk space

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 
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
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"
Enter fullscreen mode Exit fullscreen mode

Yarn and npm cache

yarn cache clean
npm cache clean --force
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

If you have some lang/tool/ide that requires cleanup leave a comment and I will add it.

Top comments (1)

Collapse
 
s0bacc profile image
S0bacc

Helped me a lot. Thanks for the guide, bookmarked it