I'm running Laravel 6 with Homestead and also ran into this problem. As suggested here in the other answers you can prefix COMPOSER_MEMORY_LIMIT=-1
to a single command and run the command normally. If you'd like to update your PHP config to always allow unlimited memory follow these steps.
vagrant up
vagrant ssh
php --version # 7.4
php --ini # Shows path to the php.ini file that's loaded
cd /etc/php/7.4/cli # your PHP version. Each PHP version has a folder
sudo vi php.ini
Add memory_limit=-1
to your php.ini file. If you're having trouble using Vim or making edits to the php.ini file check this answer about how to edit the php.ini file with Vim. The file should look something like this:
; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit = -1
Note that this could eat up infinite amount of memory on your machine. Probably not a good idea for production lol. With Laravel Valet had to follow this article and update the memory value here:
sudo vi /usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
Then restart the server with Valet:
valet restart
This answer was also helpful for changing the config with Laravel Valet on Mac so the changes take effect.