The proper way to edit files as sudo

Starting a GUI program from Terminal, for instance:
sudo gedit /var/lib/dpkg/status

... gives the error:
(gedit:17864): Tepl-WARNING **: 16:36:44.348: GVfs metadata is not supported. Fallback to TeplMetadataManager. Either GVfs is not correctly installed or GVfs metadata are not supported on this platform. In the latter case, you should configure Tepl with --disable-gvfs-metadata.

I haven't noticed any problems with starting GUI programs from Terminal as sudo, but apparently it can re-own files as root, so it's not recommended to do it that way.

A better way:
Start Nautilus
Navigate to the Home directory
Edit the .bashrc file.

My user name is 'owner', so you could also type in Terminal:
gedit /home/owner/.bashrc

At the top of the .bashrc file, add:

# Edit files by using sudoedit /{path}
export SUDO_EDITOR='/usr/bin/gedit -w'

Save the file, exit your editing program (gedit in this case) and reboot.

Then in Terminal you can use:
sudoedit /{path}

So for instance, using the same path as above:
sudoedit /var/lib/dpkg/status

1 Like

Of course, you can also install the Nautilus Admin plugin, for those who do more GUI file perusing, rather than command-line:

sudo apt install nautilus-admin

nautilus -q

Start Nautilus, find a file that normally requires you to sudoedit it, right-click it, select 'Edit as Administrator'.