So I want to run Elasticsearch on a very limited memory machine and I keep running on this error: cannot allocate memory.

Did some research and found this docs on increasing max_map_count:

echo "vm.max_map_count=262144" | sudo tee -a /etc/sysctl.conf
sudo sysctl -w vm.max_map_count=262144

But the problem still persists, turns out memory still actually still not enough. I want don’t to upgrade the memory since I just want to test things out and I have no plan on running it on production.

Swap memory to the rescue.

fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Run your elasticsearch and it should now be good.

Small Rant: I don’t get why we need more than 2GB of memory to just test ES.