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.
Pruning Docker
Let's prune Docker images first. You can see how many images you have locally and how much space each takes with
1 | $ docker images |
We can remove all image not currently used that were created more than 24 hours ago:
1 | $ docker image prune -a --filter "until=24h" |
Next you want to look at the stopped Docker containers - they are NOT deleted by default.
1 | $ docker ps -a |
Remove them
1 | $ docker container prune |
Cleaning node_modules
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.
1 | $ npm i -g npkill |
Remove old folders
You can list the folders by the last access time with:
1 | $ ls -ltu |
You can probably delete the last folders - since you only accessed them a very long time ago.
Folder size
On Mac I really enjoy using du
utility. For example, you can see the total folder size or top level plus first sublevel
1 | # 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 Option
+ Command
+ Delete
combination.
From the terminal I recommend using trash-cli that is safer to use than rm
. 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:
1 | ~/git/cypress-example-todomvc-redux on master |
And the cached versions
1 | $ 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 /path/to/cache/x.y.z
.
1 | $ ls -ltu /Users/gleb/Library/Caches/Cypress |
Each folder is quite large - unzipped Cypress is big!
1 | $ 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!
1 | $ rm -rf /Users/gleb/Library/Caches/Cypress/3* |
Much better.
Tip: if you need to re-install a Cypress binary version you have just deleted, run this command from the project that installed it:
1 | $ 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.
1 | npx cypress cache prune |
We also have introduced a command to show folder sizes and last access time for every cached binary:
1 | npx cypress cache list --size |