错误:环境中未设置XDG_RUNTIME_DIR。 Gtk-WARNING **:无法打开显示:

7

我曾经用sublime打开文本文件,对于只读文件,我过去会这样做:sudo sublime。但是现在突然间,sudo sublime命令出现以下错误:

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

虽然sublime 命令运行良好。我尝试使用gedit,但出现了相同的问题,并显示gedit错误:

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

我安装了gtk,并尝试使用gksudo,但仍然遇到相同的错误! 我在网上搜索后发现以下方式:
  1. xhost +localhosthttps://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
但以上方法都没有解决问题。 最终解决方案是:
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY sublime

从这里开始:https://askubuntu.com/questions/456689/error-xdg-runtime-dir-not-set-in-the-environment-when-attempting-to-run-naut

我想知道为什么会突然出现这个错误!另外,我想回到sudo sublime版本,因为它很容易记住。我该怎么修复呢?

另外,我最近对系统做了以下更改:

  1. 安装了Mac主题用于Ubuntu: http://www.noobslab.com/2014/04/macbuntu-1404-pack-is-released.html

  2. 安装了gksu(用于gksudo)

非常感谢您的帮助!

4个回答

3

我有同样的问题。

我的情况是因为sudo不会继承环境变量:DISPLAY XAUTHORITY

如何解决?

对于Ubuntu 14,通过sudo visudo打开sudoers文件,然后粘贴:

Defaults        env_keep += "DISPLAY XAUTHORITY"

1
如果您作为普通用户在env的输出中看到XDG_RUNTIME_DIR,那么您可能只需要使用-E开关来保留环境即可。

1

我遇到了同样的问题。是我的错,因为我按照另一个答案的方法更改了sudoers文件中的下一行:

Defaults        env_keep="https_proxy"

但我应该补充一点:
Defaults        env_keep += "https_proxy"

第一个字符串将覆盖现有列表。


1

我也在Ubuntu 14.04上遇到了同样的问题。这是因为我在跟随另一个答案时出现了问题。

按下以下键盘快捷键打开终端:

Ctrl+ Alt + T

然后输入$ sudo visudo

修改:

Defaults env_keep="https_proxy"

to

Defaults env_keep += "https_proxy"

它对我起作用了。


@Idan,感谢您提出的更改建议。您是如何进行这个更改的? - Om Prakash
同一个问题有太多答案,让人感到困惑。虽然我已经升级到16.04,不再遇到这个问题了,还是谢谢你! - Sahil Arora

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接