2

While trying to follow these instructions, I encountered the following error while attempting what seems like a simple sudo edit operation:

$  sudo gedit /var/lib/dpkg/status

** (gedit:14898): WARNING **: Command line `dbus-launch --autolaunch=0bd873023a78bdb34ca1b9650000000b --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n
Cannot open display: 
Run 'gedit --help' to see a full list of available command line options.

Running the same without sudo correctly launches gedit, but of course without editing ability. Does anyone have any idea what is going on?

Bill Cheatham
  • 1,102
  • 4
  • 14
  • 21
  • A quick workaround would be to use a console-based editor such as nano or vim, which should work without complications. I'm unsure what is causing the error - I had assumed DISPLAY was unset but testing this gives me a different error. – chronitis Nov 13 '12 at 13:30
  • And moral of the story is to stick with documentation from known sources such as https://help.ubuntu.com/community –  Nov 13 '12 at 14:15
  • @vasa1 how is that the moral of the story? Regardless of the merits of following random instructions from the internet, /var/lib/dpkg/status is a file which I should be able to edit with gedit, but currently cannot. Please, if you have a useful answer add it below. – Bill Cheatham Nov 14 '12 at 17:56
  • Hey, did you get a solution for this? Am having the same problem here. – Parto Feb 03 '14 at 08:43
  • Found a solution. Check this out http://askubuntu.com/questions/414785/cant-open-gedit-as-root/414810 – Parto Feb 03 '14 at 17:11

2 Answers2

7

You should be using gksu to launch graphical things as root.

gksu gedit /var/lib/dpkg/status
Oli
  • 293,335
  • Thanks, I hadn't heard of this. However, using this I get the error Cannot open display. I believe this is an error coming from gedit itself. – Bill Cheatham Nov 14 '12 at 17:58
  • @BillCheatham That doesn't tally with the situation. If running gedit from the same terminal works, gksu gedit should work. Anyway, try gksu gedit --display=:0 /var/lib/dpkg/status – Oli Nov 15 '12 at 00:58
  • Hmm.. I agree that it seems like it should, but it just doesn't. gedit opens gedit, gksu gedit gives an error! I think the problems run deeper than I first thought. Thanks for your help though. – Bill Cheatham Nov 15 '12 at 11:08
1

There is a known bug in 16.04 preventing root gedit from displaying the menu bar, making it somewhat useless.

The solution is to preserve environment variables while launching gedit. (Nautilus and Terminal have the same problem and fix, by the way).

gksu -k gedit
Amir Uval
  • 1,143
  • 9
  • 9