If you run out of space on your development machine, you probably have old Docker images sitting around, a giant number of
node_modules and maybe a number of old versions of Cypress test runner that you don't need anymore. Let's clean everything up.
Let's prune Docker images first. You can see how many images you have locally and how much space each takes with
$ docker images
We can remove all image not currently used that were created more than 24 hours ago:
$ docker image prune -a --filter "until=24h"
Next you want to look at the stopped Docker containers - they are NOT deleted by default.
$ docker ps -a
$ docker container prune
NPM node modules are like a black hole - they weigh a lot and nothing escapes. You can quickly see how much they take on your disk using npkill utility.
$ npm i -g npkill
Remove old folders
You can list the folders by the last access time with:
$ ls -ltu
You can probably delete the last folders - since you only accessed them a very long time ago.
On Mac I really enjoy using
du utility. For example, you can see the total folder size or top level plus first sublevel
# print just the total "github-action" folder size in human format (Megabytes)
Mac users tip
In Finder you can select and permanently delete files (without going through the Trash app) using
From the terminal I recommend using trash-cli that is safer to use than
trash-cli moves files to Trash so they can be restored.
Cleaning old Cypress binaries
Every time you install Cypress with
npm install cypress it downloads NPM package
cypress and stores it in the local
node_modules folder. Then this NPM package runs its post-install script which checks if you need to download version
x.y.z of the Cypress Electron-built binary. These binaries are stored in a central place on your machine to avoid re-downloading the same binary version again and again.
You can see where the binaries are stored:
~/git/cypress-example-todomvc-redux on master
And the cached versions
$ npx cypress cache list
Unfortunately, Cypress NPM modules does not have
cypress cache prune command yet, so you would need to delete the old folders manually. Let's see the folders - they are all named
$ ls -ltu /Users/gleb/Library/Caches/Cypress
Each folder is quite large - unzipped Cypress is big!
$ du -h -d 0 /Users/gleb/Library/Caches/Cypress/4.0.0
Let's remove all cached Cypress v3 versions - that should free up some space!
$ rm -rf /Users/gleb/Library/Caches/Cypress/3*
Tip: if you need to re-install a Cypress binary version you have just deleted, run this command from the project that installed it:
$ npx cypress install
Bonus: prune Cypress versions
Cypress v5.4.0 has added a command to prune Cypress binaries. All versions other than the one specified in the current project are pruned.
npx cypress cache prune
We also have introduced a command to show folder sizes and last access time for every cached binary:
npx cypress cache list --size