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?

5
  • 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 help.ubuntu.com/community
    – user25656
    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. Nov 14 '12 at 17:56
  • Hey, did you get a solution for this? Am having the same problem here.
    – Parto
    Feb 3 '14 at 8:43
  • Found a solution. Check this out askubuntu.com/questions/414785/cant-open-gedit-as-root/414810
    – Parto
    Feb 3 '14 at 17:11
7

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

gksu gedit /var/lib/dpkg/status
3
  • 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. 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 0: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. 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
3
  • This works but the terminal is spammed with error messages. Jul 30 '17 at 19:32
  • @WinEunuuchs2Unix you can add this to the command: 2>/dev/null
    – Amir Uval
    Aug 2 '17 at 18:35
  • 1
    You can also prefix any command with nohup for the same effect. Aug 2 '17 at 19:39

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.