so the /etc/php/cli/php.ini
has a memory_limit of 512M, that is the value you need to change, mine is showing 3G
which might be a little large but try that value to see whether it helps.
MathieuM I've tried to reduce memory_limit to 512M
the value in /etc/php/apache/php.ini
or /etc/php/fpm/php.ini
are affecting the web version only; this is the value you made available inside the phpinfo. Composer does not use that version, it uses the cli
version as BartVB initially explained.