How to fix the «Cannot create cache directory ~/.composer/cache/» Composer failure?

The cause of this issue is wrong filesystem permissions in your home directory.
You can fix it with the command:

sudo chown ${USER:=$(/usr/bin/id -run)}:$USER ~