If you are running your website on digitalocean and getting error while updating or installing new wordpress plugins and themes then this solution will help you to solve this problem.

I solved this issue by doing following two steps

1] Step 1

First login to your droplet using terminal. And run following command

sudo chown -R www-data:www-data /var/www

2] Step 2

After that you have to add following line of code inside wp-config.php

define('FS_METHOD', 'direct');

It will stop asking for FTP login details. And you can install or update existing plugin themes or wordpress easily.