RESOLVED: `npm install` ends with "Killed" | Memory Error
Errors:
1. npm install
failed
2. Killed while running npm run dev/prod/build
or other build commands
3. Ghost CMS: Unable to setup/install on low RAM
Platforms:
1. Docker
2. Ubuntu/Linux
Reason:
Due to less physical memory(RAM) on the system or server.
Solution:
Increase RAM or create swap memory to handle the load.
Make a swap file twice the size of the physical memory. Here's something to think about: although though a smaller swap partition is an option and would usually be sufficient, if you want this system to be rock-solid stable, I would recommend going with the 8 GB recommended.
In reality, I advise using 2 * RAM plus 1 MB so that there is unquestionably space for switching out 2 full copies of memory. This prevents the "shell game" scenario, which could have a severe impact on performance.
If physical memory is of 1GB then, create 2GB swapfile,
these are commands to run on shell.
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl vm.vfs_cache_pressure=50
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
Thanks!