Annoying Gtk warning, how to fix it

It is possible that when using the sudo command in combination with Pluma (or Gedit) an error message appears in the terminal, for example:

(gedit:8305): Gtk-WARNING **: Attempting to store changes into `/root/.local/share/recently-used.xbel', but failed: Failed to create file '/root/.local/share/recently-used.xbel.3VXH3V': No such file or directory

(gedit:8305): Gtk-WARNING **: Attempting to set the permissions of `/root/.local/share/recently-used.xbel', but failed: No such file or directory

The error shows that Gtk attempting to get read/write access and try to access a file in the directory /root/.local/share/. This folder does not exist and has to be created manually. I ran into this error under Linux Mint with the MATE desktop environment, but is doesn't harm to follow the instructions below.

Just to be sure that the folder mentioned in the error message really doesn't exist you can run the last terminal command before following the instructions below. If the folder does exist, then you're all settled!

The solution to manually creating this folder by doing the following:
  • Open a terminal

  • Type the following command:
    sudo mkdir -p /root/.local/share
To check if this directory is created type the following command in the terminal:
  • sudo ls /root/.local/

It is important to start with the command sudo since you need root access to look into the root folder. Normal users have no write/read access in the above mentioned directory since a normal user doesn't has root privileges. 

Other solution:

Another solution to avoid such problems as above, is not using sudo to start and run graphical programs but to use gksudo instead. The command gksudo sets HOME=~root, and copies .Xauthority to a tmp directory. This prevents that files in your home directory becomes owned (and used) by root.