I am attempting to run nautilus as root but when I run "sudo nautilus" from the terminal, I get the following error:

error: XDG_RUNTIME_DIR not set in the environment.

(nautilus:9341): Gtk-WARNING **: cannot open display:

The issue does not occur when I attempt to run nautilus as non-root. I am using ubuntu 14.04. Does anyone know how I can fix this?

share|improve this question
    
Just for the record, I ended up here after I had the same error come up when trying to do X11Forwarding via ssh. Solution: I had forgotten to use the -X option when starting my ssh session. – JW. May 15 '15 at 11:47
up vote 10 down vote accepted

When you run software as another user you're in fact starting the new minimal and isolated environment that doesn't carry on some "excessive" variables (among others variables responsible for injecting libraries or setting certain privileges). Replace your sudo nautilus call with the following - it will carry on user-specific x server settings from the current session:

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY nautilus
share|improve this answer
1  
Awesome! Thank you! – quantumbutterfly May 20 '14 at 14:41
1  
@Cyprian Guerra - This doesn't set in to the environment, this only lets you run one time. This is hardly helpful. Running sudo nautilus should work as normal from terminal when run. Normally whenever I do that from terminal on a fresh install it opens up as normal with sudo. – user94959 Mar 4 '15 at 10:57
    
@user94959 You don't understand the basic principle - the new environment is being set, the variables are carried over, the task runs, when the task exits this separate environment is being destroyed. Therefore yes, you need to set the variables for every new environment. If you wish more reading material try pkexec and sudo man pages as well as google for the related dispute. – cprn Mar 4 '15 at 16:43
1  
@sherrellbc I'm telling explicitly policy kit to run env before running nautilus and the former takes care for setting the variables for me. You can check man env. – cprn Aug 21 '17 at 13:54
1  
@cprn D'oh. I should have checked the man page first. env COMMAND ARG ... – sherrellbc Aug 21 '17 at 18:29

I also had the same problem on Ubuntu 14.04. Open terminal by pressing,

Ctrl + Alt+ T

then sudo visudo

change the line

Defaults env_keep="https_proxy"

to

Defaults env_keep += "https_proxy"

It worked for me.

share|improve this answer
    
It works but setting same for $XAUTHORITY defies the purpose. – cprn Aug 21 '17 at 13:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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