How to increase memory (RAM) on DigitalOcean Droplets for free
Daisho Komiyama edited this page Dec 27, 2021
·
2 revisions
Troubleshoot
npm install
won't complete. It tries, but ending up throwing errors as follows;
npm ERR! code ENOMEM
npm ERR! syscall spawn
npm ERR! errno -12
npm ERR! spawn ENOMEN
This is because the machine doesn't have enough memory. Happened to me with a VPS from DigitalOcean which was provisioned with 1GB of RAM. 1GB may not enough for a Gatsby app. High memory usage was observed for a build process too.
A swap file can be a solution. I wondered if the droplet had it set up?
free -m
And the output suggested that there is no swap file provisioned. This is how the output looked;
total used free shared buff/cache available
Mem: 492 109 280 4 102 366
Swap: 0 0 0
So we need to set up a swapfile.
sudo fallocate -l 1G /swapfile
I could have done with 2GB, but I allocated 1GB for my droplet.
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s
Filename Type Size Used Priority
/swapfile file 2097148 44088 -1
To make the swap file permanent, we need to add it to /etc/fstab
file. Add the following line to the /etc/fstab
file.
/swapfile none swap sw 0 0
After doing all the above, npm install
start to be completed successfully.
Gatsby's build process completes a lot faster now 🤗