3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

X11 が MobaXterm の WSL2 で起動しないときの対処法

Last updated at Posted at 2020-07-22

WSLg を使って X11 の機能を使うときには、以下の設定は邪魔になるので DISPLAY=:0 にしてください。

困ったこと

MobaXterm を使っていて WSL2 で X11 アプリケーションを開こうとしたら怒られたので解決方法メモ。以下のように怒られる。

$ xeyes
Error: Can't open display: 127.0.0.1:0.0

解決方法

/etc/resolv.conf にある nameserver の IP アドレスを確認する。

$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 192.168.11.1

この例でいう 192.168.11.1 を用いて環境変数 DISPLAY を以下のように設定する。

$ export DISPLAY=192.168.11.1:0

これで X11 ウィンドウが表示できるようになった。

シェル起動時に自動で設定させる方法

環境変数 DISPLAY は起動するたびに変更されてしまうので、bashrc などに 1 行書いておくとよい。

export DISPLAY=`cat /etc/resolv.conf | grep nameserver | awk {'print $2 ":0"'}`

参考資料

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?