Increase the maximum allocated memory in your /etc/apt/apt.conf. Add this line if it does not exist (also create /etc/apt/apt.conf if necessary):

APT::Cache-Limit 30000000;