0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MSYS2 の bash から何故か WSL bash が起動しないので対処方法を考えた

Posted at

序文

今までの作業環境がかなり汚れてきたので、もう一台のマシンをクリーンインストールしていろいろセットアップしていたら、なんか MSYS2 の bash から WSL bash が起動しないんですけど?
でもコマンドプロンプトや PowerShell からは普通に起動するぞ?
MSYS2 の bash でも一度 cmd.exe を立ち上げたあとは起動するぞ?
という謎の状況の対処の為にスクリプトを経由して起動する事にしました。

作成したスクリプトファイル

~/msys2-files/scripts/wsl.sh
#!/bin/sh
# note: If you put this file on ~/bin, you can omit an additional path setting.
cmd.exe //C "wsl.exe --distribution Ubuntu-24.04 bash"

パスの追加 (自分の配置場所の場合)

~/.bash_profile(excerpt)
PATH="${HOME}/msys2-files/scripts:${PATH}"

もしくは

cat <<'EOF' >> ~/.bash_profile
PATH="${HOME}/msys2-files/scripts:${PATH}"
EOF

終わりと蛇足

これで wsl.sh で起動するようになりました。
スクリプトを置くパスはお好みで、パスの追加をしなくてよくなるので一番楽なのは ${HOME}/bin に配置する事です。

自分の場合は Explorer で複数の自分の名前のディレクトリの区別ができない等の理由から、こういう感じの名前で保存する事にしています.
(シリーズで local-filesonedrive-files, wsl-files などの名前にしてあります。mac の時は mac-files で Parallels の Windows のほうが local-files になってしまいましたが!!)

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?