LoginSignup
4
0

More than 3 years have passed since last update.

WSL2からVisual Studio Codeを起動する

Last updated at Posted at 2020-10-03

しばらくWindows10上のWSL2からLinuxが起動できない状況でしたが、
以下のWindowsUpdateでWSLが起動するようになりました(2020年10月1日現在)。

Announcing Windows 10 Insider Preview Build 20226

PS C:\> cmd /c ver
Microsoft Windows [Version 10.0.20226.1000]

今まではVisual Studio Codeを起動してから、リモートウインドウを開いていましたが、
コマンドライン(PowerShell)から起動する方法が判りましたので、メモしておきます。

PowerShellからVisual Studio Codeを起動する方は以下の通りです。

ディストリビューションはUbuntu-20.04を使用しています。

PS C:\> wsl -d {ディストリビューション名}

wslコマンドの他にディストリビューション名が付いた実行ファイルがあります。
例えばUbuntu 20.04 LTSの場合ubuntu2004.exeという名前になります。

PS C:\> ubuntu2004 run code

ショートカットを作成します

ワンクリックで起動できるようにショートカットを作成しておきます。

ubuntu2004.exeコマンドのフルパスを調べます

当然、whichコマンドは無いですね。

PS C:\> which ubuntu2004
which: The term 'which' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\> (gcm ubuntu2004).Definition
C:\Users\nandymak\AppData\Local\Microsoft\WindowsApps\ubuntu2004.exe
PS C:\>

ショートカットを登録します

ショートカットのリンク先に以下を登録します。

C:\Users\nandymak\AppData\Local\Microsoft\WindowsApps\ubuntu2004.exe run code

ショートカットから起動します。

作成したショートカットをダブルクリックで、一瞬コンソールが表示された後に、VSCodeがWindows側で起動します。
image.png

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