Composer update `The following exception is caused by a lack of memory and not having swap configured` error in vagrant

It isn't a bug and fix it - To enable the swap you can use for example:

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1


Hope it will help you :)

Sometimes swap file has not enough memory for composer update, so create a new one:

(assuming existing /swapfile has 2G, create new /swapfile1 with 8G of your drive space)

$ sudo fallocate -l 8G /swapfile1
$ sudo chmod 600 /swapfile1

$ sudo mkswap /swapfile1
$ sudo swapon /swapfile1

after composer updated, you can remove it and keep only initial file:

$ sudo swapoff /swapfile1
$ sudo rm /swapfile1

This thread suggest that their will not be any fix for that.

Here are two workarounds. You can use each separately or both at the same time.

1st workaround: increase memory limit for the command

In the vagrant machine. Increase the php memory limit for the current command. Run:

php -dmemory_limit=2G /path/to/composer update

2nd workaround: increase guest machine memory

Add this configuration to your vagrant file, so you can temporary increase allocated memory:

$MEMORY = ENV.has_key?('VM_MEMORY') ? ENV['VM_MEMORY'] : "512"

Vagrant.configure("2") do |config|
    config.vm.provider "virtualbox" do |v|
        v.memory = $MEMORY

Then reload your vagrant machine as follow: VM_MEMORY=2048 vagrant reload

Then, in your vagrant machine, run composer update.