## 事象 [[WSL]]で[[wl-clipboard]]のコマンド (`wl-copy` など) が動かない。[[WSL]]の[[Ubuntu 22.04 LTS|Ubuntu 22]]を[[Ubuntu 24.04 LTS(Noble Numbat)|Ubuntu 24]]に更新したあとから発生している。 ```error $ wl-copy Failed to connect to a Wayland server: No such file or directory Note: WAYLAND_DISPLAY is set to wayland-0 Note: XDG_RUNTIME_DIR is set to /run/user/1000/ Please check whether /run/user/1000//wayland-0 socket exists and is accessible. ``` ### 環境 | 対象 | バージョン | | ---------------- | -------------------- | | [[Ubuntu]] | 24.04.1 LTS (in WSL) | | [[WSL]] | 2.2.4.0 | | [[wl-clipboard]] | 2.2.1 | | [[Windows 11]] | 10.0.22631 | ## 原因 `${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}` で期待されるパスのソケットファイルにアクセスできていないから。[[Wayland]]サーバーに接続できない。 ## 解決方法 `.bashrc` や `.zshrc` で [[WSLg]]のソケットから`${XDG_RUNTIME_DIR}` 配下への[[シンボリックリンク]]を作成する。 ```bash if [ ! -S "$XDG_RUNTIME_DIR/wayland-0" ]; then ln -s /mnt/wslg/runtime-dir/wayland-0* "$XDG_RUNTIME_DIR" fi ``` これで `/run/user/1000/wayland-0` にアクセスできるようになる。 ```console $ echo $XDG_RUNTIME_DIR /run/user/1000/ $ ll $XDG_RUNTIME_DIR | grep wayland lrwxrwxrwx - 22 Jan 00:07 wayland-0 -> /mnt/wslg/runtime-dir/wayland-0 lrwxrwxrwx - 22 Jan 00:07 wayland-0.lock -> /mnt/wslg/runtime-dir/wayland-0.lock ``` ## 参考 <div class="link-card-v2"> <div class="link-card-v2-site"> <img class="link-card-v2-site-icon" src="https://static.zenn.studio/images/logo-transparent.png" /> <span class="link-card-v2-site-name">Zenn</span> </div> <div class="link-card-v2-title"> WSL2(2.1.5.0)でWSLg周りがうまく動作しないことに対するワークアラウンド </div> <img class="link-card-v2-image" src="https://res.cloudinary.com/zenn/image/upload/s--0ZpKh4nM--/c_fit%2Cg_north_west%2Cl_text:notosansjp-medium.otf_55:WSL2%25282.1.5.0%2529%25E3%2581%25A7WSLg%25E5%2591%25A8%25E3%2582%258A%25E3%2581%258C%25E3%2581%2586%25E3%2581%25BE%25E3%2581%258F%25E5%258B%2595%25E4%25BD%259C%25E3%2581%2597%25E3%2581%25AA%25E3%2581%2584%25E3%2581%2593%25E3%2581%25A8%25E3%2581%25AB%25E5%25AF%25BE%25E3%2581%2599%25E3%2582%258B%25E3%2583%25AF%25E3%2583%25BC%25E3%2582%25AF%25E3%2582%25A2%25E3%2583%25A9%25E3%2582%25A6%25E3%2583%25B3%25E3%2583%2589%2Cw_1010%2Cx_90%2Cy_100/g_south_west%2Cl_text:notosansjp-medium.otf_37:7e%252B8%2Cx_203%2Cy_121/g_south_west%2Ch_90%2Cl_fetch:aHR0cHM6Ly96ZW5uLWRldi5naXRodWIuaW8vZGVmYXVsdC1hdmF0YXJzL2Rhcmsvai5wbmc=%2Cr_max%2Cw_90%2Cx_87%2Cy_95/v1627283836/default/og-base-w1200-v2.png" /> <a href="https://zenn.dev/junkor/articles/cf64671f4fc637"></a> </div>