"xdg_runtime_dir not set in the environment" and pkexec doesn't work

Orian Zinger picture Orian Zinger · Dec 11, 2014 · Viewed 34.5k times · Source

I try to execute the following line on ubuntu-server 14.04:

$ sudo gedit /usr/local/svn/passwd-team

and I get this error:

error: XDG_RUNTIME_DIR not set in the environment.

(gedit: 11805): Gtk-WARNING **: can not open display:

I Googled for help and saw that I had to write:

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY gedit

Then I got the following message:

=== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authenticating is needed to run '/usr/bin/env' as the super user
Authenticating as: student,,, (student)
Password:
no talloc stackframe at ../source3/param/loadparm.c:4864, leaking memory
=== AUTHENTICATING COMPLETE ===
error: XDG_RUNTIME_DIR not set in the environment.
7
(gedit: 11807): Gtk-WARNING **: can not open display:

Now what? I just want to edit passwd-team file. please guide me. Thanks a lot, Orian.

Edit: I used nano to edit that file, but the error is still there.

Answer

Prateek Mishra picture Prateek Mishra · Oct 12, 2015

I have faced similar issues when using gedit after i ssh into any other user.This may be due to missing permission.

Try the following :-

Open a new terminal from your current user. type in

sudo -i

This prompts for root password. Enter that and then you will be in able to access using root privilege.

Then Try Gedit the file you want to edit. If you need to do it using su for other user then after the above step, do

su <username>

Now Try gedit any file. Works for me.