Out of memory error in composer when requiring drupal/bootstrap I currently set up a Drupal 8 website using Composer like described here.
Drupal is already running. Now I want to add Bootstrap theme by calling

composer require drupal/bootstrap


But I get


  Using version ^7.3 for drupal/bootstrap
  ./composer.json has been updated
  DrupalProject\composer\ScriptHandler::checkComposerVersion
  Loading composer repositories with package information
  Updating dependencies (including require-dev)
  
  mmap() failed: [12] Cannot allocate memory
  
  mmap() failed: [12] Cannot allocate memory
  PHP Fatal error:  Out of memory (allocated 515907584) (tried to allocate 20480 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Pool.php on line 221
  
  Fatal error: Out of memory (allocated 515907584) (tried to allocate 20480 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Pool.php on line 221


Im using Composer version 1.2.1 2016-09-12 11:27:19
This is related to your php.ini file's memory_limit entry which defaults to 128M. You need access to your server's php configuration file. If you do here is the step by step for making that change on an Ubuntu server with PHP 7 and PHP CLI extension.


Open the PHP CLI configuration file located at /etc/php/7.0/cli; e.g. I use vim as follows sudo vim /etc/php/7.0/cli/php.ini
Search for the line containing memory_limit by pressing the / (forward slash) key, type the phrase memory_limit and press enter.
Once on that line go to vim's insert mode by pressing 'ESC' followed by 'i'. 
Change the value for the memory_limit to something higher, e.g. memory_limit = 1024M since you already have 512M for the limit.
Save and exit the configuration file by pressing 'ESC' type in 'wq' and then press 'enter'.


If you don't see any changes it could be that you have an error in you php.ini configuration file. You are always welcome to comment on the answers to get more help.