WSLあれこれ
WSLで躓いたこと困ったこと解決したことをつらつらり
WSLの再起動
# ディストリビューションの一覧を表示
> wsl -l -v
# 停止
> wsl -t <dist_name>
# 再度terminalからWSLにつなぐなりすれば動き出す
# or
# 管理者権限のPowershellから実行
> Restart-Service LxssManager
Windowsの環境変数がUbuntuの$PATHに含まれてる
Ubuntu側の/etc/wsl.conf
ファイル(なければ作る)に以下を記述
[interop]
enabled = false
appendWindowsPath = false
ubuntuを再起動すると反映される。
ディストリビューションを閉じて8秒ほどたつと再起動されるのでwsl --list --running
コマンドで逐一起動しているディストリビューションがあるか確認し、起動しているディストリビューションがなければ再度ディストリビューションを起動すると設定が反映されてる
❯ wsl --list --running
実行中のディストリビューションはありません。
code
コマンドでVSCodeが起動しない
$ code .
Command is only available in WSL or inside a Visual Studio Code terminal.
code
コマンドで呼び出されているのは、vscode-server
でWindows側に入っているVSCodeではない。
これはappendWindowsPath = false
に設定してWindows側のPathがUbuntuに通っていないため。
従ってWindows側のVSCodeのパスをUbuntuの$PATHに追加してやればよい。
# パスは適宜変えてね
export PATH=$PATH:"/mnt/c/Users/username/AppData/Local/Programs/Microsoft VS Code/bin"
appendWindowsPath = true
に戻せない???
appendWindowsPath
をfalseにした後trueに戻したけどPATHが変わらない。元に戻せない???
wslpath
windows ⇔ WSL 間でパス文字列を変換
wslpath <windowsのパス>
# -> wslのパス
wslpath -w <wslのパス>
# -> windowsのパス
Proxy
.bash_profile
export http_proxy="http://proxy.example.com:port"
export https_proxy="http://proxy.example.com:port"
export no_proxy="http://proxy.example.com:port"
/etc/apt/apt.conf
Acquire::http::Proxy "http://proxy.example.com:port";
Acquire::https::Proxy "http://proxy.example.com:port";
/etc/wgetrc
https_proxy = http://proxy.example.com:port
http_proxy = http://proxy.example.com:port
ftp_proxy = http://proxy.example.com:port
VSCode
WSL拡張を入れる
これ入れてからWSL上でCode実行しないとうまいことしてくれない
terminal
bash_profileが読み込まれない
To get the development tools on the $PATH, VS Code will launch a bash login shell on startup. This means that your ~/.bash_profile has already run and when an integrated terminal launches, it will run another login shell, reordering the $PATH potentially in unexpected ways.
[翻訳] VS Codeは、$PATH
上の開発ツールを取得するために、起動時にbashログインシェルを起動します。つまり、~/.bash_profile
は既に実行されており、統合ターミナルを起動すると別のログインシェルが実行され、$PATH
が予期せぬ順序で変更される可能性があります。
ohmyposhの起動を.bash_profile
に書いていたがVSCodeでは起動しなかったため.bashrc
にも書いた。2重で書いてていいかよくわかってないのでちゃんと理解したい
# .bashrc と .bash_profile の両方に書いた
eval "$(oh-my-posh init bash --config $(brew --prefix oh-my-posh)/themes/takuya.omp.json)"
terminal起動すると.bashrc
が2回呼び出されてる気がする