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. How do I fix a "cannot open display" error when opening an X program after ssh'ing with X11 forwarding enabled?

None of the above worked.

What worked out for me was :


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!

  • Have you tried sudo env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" sublime? (In any case, you should always quote all shell variables references unless you have a good reason not to.)
    – Scott
    Sep 22 '20 at 5:43

Any system updates lately... This sounds related. Maybe this

If you have something that works, you can always just put it in a shell script and keep that script in your path.
In Debian you can create a 'bin' directory in your home folder and that will automatically be included in your path; I'm not certain if it works on Ubuntu, but chances are good.

So in ~/bin create 'sublime-root.sh' and put your pkexec stuff in there?

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.