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.

You are watching: 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?


When you run software as another user you"re in fact starting a new minimal isolated environment that doesn"t carry on some "excessive" variables (among others variables responsible for injecting libraries or setting 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 nautilusThis is a one time low level solution but it will work on a misconfigured machine. If you want to permanently "fix your sudo" you need to find the issue with your environment configuration and correct it as described in other answers.


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"


Defaults env_keep += "https_proxy"

It worked like charm.


To make it easy - more explained the new booting of my system.

After all explanations here I came to the result - and "env" in terminal said already that is right for these session:

These two rows to use the environment variable:

for the tmp behavior I have chosen:

mkdir -pv ~/.cache/xdgr

For setting the environment variable:

export XDG_RUNTIME_DIR=$PATH:~/.cache/xdgr

After closing the terminal and a new open for the recall of env they tells:


note: it is ok for the user under ubuntu, root need more (last info by term - with 0700 permissions)


If you are getting this error in Docker ; this is what I do

# sudo xhost +access control disabled, clients can connect from any host# export DISPLAY=:0.0# docker run -it --env DISPLAY=unix$DISPLAY --privileged --volume /tmp/.X11-unix:/tmp/.X11-unix .. rest of your Docker arugments


Thanks for contributing an answer to Ask Ubuntu!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

See more: Great Falls Rescue Mission Thrift Store Needs Volunteers, Current Needs

To learn more, see our tips on writing great answers.

Post Your Answer Discard

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 nautilus sudo or ask your own question.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.10.29.40598

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.