Managing disk space on your development machine/server can be pretty annoying if you don't know where to start. In this article I've compiled some important places to check, especially if your environment includes Docker, Python or Node. I'll be focusing mostly on macOS and Linux, but similar commands are also applicable for Windows.
Useful commands
- Use
df -hto see the full disk usage - Use
du -sh <folder-name>to see the size of a certain folder
Development environment
Docker
docker system df- prints the size of images, containers and cachedocker builder prune- clears docker cache, used for image building (doesn't remove anything important)
Conda & Python
conda env listorconda info --envs- list all environmentsconda remove -n <env-name> --all- remove any unused environmentsconda clean --all- clean up all files that were left by removed environmentspip cache purge- clean pip cacheuv cache clean --force- clean uv cache
NVM & Node
rm -rf ~/.nvm/.cache- clean nvm cacherm -rf ~/.npm/_npx- clean npx temp packages
Additional shell startup speed-up
NVM is initialized whenever a new shell is opened (as defined in ~/.zshrc).
To only load it when the user requests it, do the following:
# replace
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
### with
export NVM_DIR="$HOME/.nvm"
export PATH="$NVM_DIR/versions/node/v22.12.0/bin:$PATH"
nvm() {
unset -f nvm
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
nvm "$@"
}
node and npm will continue to work immediately, while nvm.sh loads only when nvm is called. In the configuration above, swap v22.12.0 for your default version.
macOS
- To look up which files on your system are taking the most space go to
Settings > Storage > Documents > File browser. Then navigate the tree and remove unnecessary files. rm -rf ~/Library/Caches/*- deletes temporary caches for programs (you might have to re-log in)
Homebrew
Auditing what is installed
To find out what you installed using the brew command, use the following:
brew leaves # top-level formulas (what you installed on purpose) - we are mostly interested in this
brew list --cask # GUI apps
brew deps --installed --tree | less
After that, remove any formula that you don't need by using brew uninstall.
Cleanup
Start by removing orphaned dependencies and old caches. This step is completely safe.
brew autoremove
brew cleanup --prune=all
Removing redundant runtimes
If you use conda or e.g. nvm for version management, you can also remove stale versions python@*, node@*.
brew uses --installed python@3.11 # check nothing depends on it first
brew uninstall python@3.11 node@14
Linux
rm -rf /tmp/*- remove temporary files
Journal logs:
journalctl --disk-usage- see the disk usage for logssudo journalctl --vacuum-time=7d- remove logs older than 7 days
APT
sudo apt-get cleanandsudo apt-get autoclean- clean up unused files- Remove unnecessary packages:
sudo apt-get --dry-run autoremove --purgesudo apt-get autoremove --purge