This is a **permission issue** and you can fix it just running the below command.
<br>It will work but you need to give permission every time.

    sudo chmod -R 777 var/;sudo chmod -R 777 pub/;sudo chmod -R 777 generated/;
**or**<br><br>
**Perfect solution** - need to give one time permission
[https://devdocs.magento.com/guides/v2.4/install-gde/composer.html#set-file-permissions][1]

    cd /var/www/html/<magento install directory>
    find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
    find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
    chown -R :www-data . # Ubuntu
    chmod u+x bin/magento

**Hope it will work for you.**


  [1]: https://devdocs.magento.com/guides/v2.4/install-gde/composer.html#set-file-permissions