"Cannot create cache directory /home/<user>/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache"

if anyone pass through here, this is shorter solution:

sudo chown -R $USER $HOME/.composer

it seems to me the group information is missing in your command

sudo chown -R <user> /home/<user>/.composer/cache/repo/https---packagist.org

Shoud be

sudo chown -R <user>:<group> /home/<user>/.composer/cache/repo/https---packagist.org

But to avoid other permission issues, I would rather advise:

sudo chown -R <user>:<group> /home/<user>/.composer/cache

(you'll need access to other folders in there) and

sudo chown <user>:<group> /home/<user>/.composer

To make sure your user has permissions enough on the global composer folder. Mind the missing recursion so the user don't own keys created by root. If you need to find out the group:

groups <user>