This is a permission issue and you can fix it just running the below command.
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/;
Hope it will work for you.or
Perfect solution - need to give one time permission
https://devdocs.magento.com/guides/v2.4/install-gde/composer.html#set-file-permissions
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.