RuntimeException vendor does not exist and could not be created

Googlers, do not use composer with sudo:

Add your user in the www-data group (this action require you to logout and login again)

sudo usermod -a -G www-data `whoami`

Give the right permissions to /var/www

sudo chown root:root /var/www
sudo chmod 755 /var/www/

Give these permissions to your project

sudo chown -R www-data:www-data /var/www/<project>
sudo chmod -R 774 /var/www/<project>

@Etienne Gautier's solution will certainly work.

Another solution is just to change the permissions of the user/group of /vendor.

e.g.

sudo chmod -R 775  /ROOT_OF_YOUR_APP/vendor/
sudo chown -R $USER:$USER /ROOT_OF_YOUR_APP/vendor/

if you are a linux user, run the following command

sudo chown -R user projectFolder/

then run composer install. user is the username of your machine. If you are not sure just run

whoami

from the terminal