error: XDG_RUNTIME_DIR not set in the environment. Gtk-WARNING **: cannot open display:
Asked Answered
C

4

7

I used to open text files with sublime, and for Read-only files, I used to do : sudo sublime. But now just suddenly the sudo sublime command gives the following error :

(sublime:3931): Gtk-WARNING **: cannot open display:

while sublime command is working fine. I tried the same with gedit, and the same thing happened, with the error with gedit being shown :

error: XDG_RUNTIME_DIR not set in the environment.
(gedit:3933): Gtk-WARNING **: cannot open display: 

I installed gtk, and tried gksudo, still got the same error!

I searched the web and found these ways :

  1. xhost +localhost : https://askubuntu.com/questions/614387/gksu-gtk-warning-cannot-open-display-0
  2. export DISPLAY=:0.0 :
  3. ssh username@hostname -X
  4. ssh username@hostname -Y
  5. https://superuser.com/questions/310197/how-do-i-fix-a-cannot-open-display-error-when-opening-an-x-program-after-sshi

None of the above worked.

What worked out for me was :

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY sublime

From here : https://askubuntu.com/questions/456689/error-xdg-runtime-dir-not-set-in-the-environment-when-attempting-to-run-naut

I want to know why exactly am I getting this error, that too suddenly! Also, I want to get back to the sudo sublime version, since it is easy to remember. How can I fix that?

Also, the recent changes I did to the system were :

  1. Installed Mac theme for Ubuntu : http://www.noobslab.com/2014/04/macbuntu-1404-pack-is-released.html

  2. Installed gksu(for gksudo)

Help would be highly appreciated!

Chemosynthesis answered 17/10, 2015 at 13:25 Comment(0)
N
3

I have the same problem.

The reason in my situation is that sudo does NOT inherit environment variables: DISPLAY XAUTHORITY.

HOW TO FIX?

For Ubuntu 14, open sudoers file via sudo visudo, then paste:

Defaults        env_keep += "DISPLAY XAUTHORITY"
Necessary answered 28/2, 2016 at 6:32 Comment(0)
A
1

Had same problem. My fault that i followed another answer and changed file sudoers with next string:

Defaults        env_keep="https_proxy"

But i should have added that:

Defaults        env_keep += "https_proxy"

First string overrides existing list.

Antons answered 21/7, 2016 at 17:9 Comment(0)
A
1

I also had the same problem on Ubuntu 14.04. It was caused while following another answer. Open terminal by pressing,

Ctrl+ Alt + T

then $ sudo visudo

change

Defaults env_keep="https_proxy"

to

Defaults env_keep += "https_proxy"

It worked for me.

Alixaliza answered 1/8, 2016 at 12:4 Comment(2)
@Idan, thanks for suggesting change. How did you make that change?Alixaliza
There are too many answers on the same question. Too confusing. Though I upgraded to 16.04 and am not facing this anymore, thanks anyways!Chemosynthesis
S
1

If you see XDG_RUNTIME_DIR in the output of env as a regular user, then all you probably need to do is use the -E switch to preserve the environment.

Shizukoshizuoka answered 28/1, 2018 at 23:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.