Cannot open GUI editors in superuser mode

You shouldn’t run an editor as root to edit system files, you should use sudoedit (especially since you have sudo set up already). That will make a copy of the file, that you can edit, open it in the editor of your choice, wait for you to finish editing it, and if you make changes to it, copy it back over the system file.

In a little more detail, you’d run something like

SUDO_EDITOR="gedit -w" sudoedit /etc/apt/sources.list

This will:

  • check that you’re allowed to edit the file (according to the sudo configuration in /etc/sudoers; yours should be OK already);
  • copy /etc/apt/sources.list to a temporary file and make it editable for you;
  • start gedit with the temporary file;
  • wait for you to close the file (this is why we need the -w option);
  • check whether you made changes to the temporary file, and if so, copy it over the original file.

You can set SUDO_EDITOR up permanently in your shell’s startup files (e.g. ~/.bashrc). If it’s not defined, sudoedit will also check VISUAL and EDITOR. You can specify any editor you like, as long as it’s capable of waiting for an editing session to finish.