It could be a result of either local file permissions or WordPress configuration.
To fix local file permissions, you can either:
If you have root shell access (such as on a VPS server) you can run something like:
sudo chown www-data:www-data * -R
sudo usermod -a -G www-data YOUR-USERNAME-HERE
This ensures that the groups and permissions are set correctly.
Change the file and directory permissions to 775 (or 777 if that fails) so that PHP can write to the necessary files/folders. For best security (especially if you're on a shared host), some recommend only doing this temporarily for performing updates and then removing the write permissions again afterward.
More rarely, this error can also occur if your WordPress configuration in
/wp-config.php is set to use something like:
define( 'FS_METHOD', 'ftpext' );
This tells WordPress that it needs to use FTP to make file changes instead of working directly with the local file system. The line will likely be followed by FTP login information. If this login information is incorrect then WordPress will be unable to login and perform file-system changes.