On low memory machines, you might run into an error like this when running yarn
:
Killed
error Command failed with signal "SIGKILL".
This may be because the machine is running out of memory. To fix this, you can add swap to the machine. This will allow the machine to use disk space as memory when it runs out of RAM.
Please note that this is not something that you should do on a production machine, as it will have unintended consequences on memory backed services. However, if you’re running a small EC2 instance for a hobby project, this is a great way to get around the memory limitations of the machine.
Its a simple procedure to add 1 gigabyte of disk backed swap memory to your machine. Just run the following commands:
sudo fallocate -l 1G /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
And that’s it! You should now be able to run yarn
without running out of memory.