Composer Update: Allowed memory size exhausted

When I run composer update, I got memory limit error:

Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 167772160 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleSet.php on line 90

Tried solution from here:
https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors

Same error when I try:

$ COMPOSER_MEMORY_LIMIT=-1 composer update

Checked PHP memory limit:

$ php -i | grep memory_limit 
memory_limit => 2G => 2G   

PHP memory limit is set to 2GB.

So, to set unlimited memory limit, I ran the following command:

$ php -d memory_limit=-1 composer update 
Could not open input file: composer

Got this error: Could not open input file: composer

Finally was able to run with the following command (by providing the full path of the composer):

$ which composer 
/usr/local/bin/composer 
$ php -d memory_limit=-1 /usr/local/bin/composer update   

Hope this helps. Thanks.