Cleaning AWS EC2 space . Resolve : “ENOSPC: no space left on device”
Today I will describe how i thought I have a server storage leakage but it was yarn and nvp. Before using yarn I had an npm install. That also occupied most of the space.
Environment description
OS — ubuntu 22.0
node — v18.6.0
npm — 8.14
To check the storage fire up your terminal and follow -
$ df -h
Then run
$ cd /
$ sudo du -ah . | sort -rh | head -20
# In rare cases, where your disk is really really full and sort
# doesn't work due to that, you can run the following to
# clean up apt-get cache. Alternatively, you can remove certain
# files/folders that you are sure unused.
$ sudo apt-get clean
Let’s have a quick breakdown on what the commands above are doing:
cd /
to change directoy to our/
.du -ah .
get all files and directories (-a
) and print the sizes in a human readable format (-h
)sort -rh
sort the result in the reverse order (-r
) by comparing human readable numbers, e.g., 2K 1G (-h
)head -20
basically take the top 20 results of the sorted list.sudo apt-get clean
to clean up apt package cache if the above command can’t be run due to disk space being too full.
More commands to clean different cache folders which takes up space
$ sudo yarn cache clean
$ sudo npm cache clean --force
$ sudo nvm cache clean
For fixing sys files you can run
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get autoremove
Now run again
$ df -h
and see how many space is there now. This type of problem can slow down your entire application process. There can be also other types of reason for these.