I was trying to edit my sources.list in order to add local mirror information. I am not comfortable with command line editors, so I tried using sudo mousepad /etc/apt/sources.list.

I got the following error report.

No protocol specified

(mousepad:4942): Mousepad-ERROR **: Cannot open display: 

I tried several other editors such as gedit, kwrite etc. but I get similar error reports.

No protocol specified

** (gedit:4957): WARNING **: Could not open X display
No protocol specified
Unable to init server: Could not connect: Connection refused

(gedit:4957): Gtk-WARNING **: cannot open display: :0

I am on a local 64 bit system running Debian Jessie.


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.

| improve this answer | |

Input sudo apt edit-sources to open your sources list in nano.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.