WindowsPCでUbuntuを使えるようにする
今回は今まで使っていたPCが壊れたので、新規に環境構築をしなければならなくなったので方法をメモしておこうと思います。
マシンスペック
OS: Windows 10 Pro(64bit)
CPU: Intel Core i7-6700K@4.00GHz
メモリ: 16GB
wslをインストールする
WindowsでUbuntuを使えるようにするにはWSL(Windows Subsystem for Linux)をインストールする必要がある。
Windows PowerShellを管理者として実行し、下記コマンドでwslをインストール
wsl --install

誘導通りにPCを再起動すると勝手にターミナルが立ち上がり以下の表記が現れ、username、パスワードの設定を促されるので設定する。

Ubuntuのバージョンは特に指定しなかったので24.04がインストールされました。
#Ubuntuのバージョン確認コマンド
lsb_release -a

リポジトリのパッケージ情報を更新し、最新バージョンをインストール。
sudo apt update
sudo apt upgrade
VS Codeのインストール
私の場合、WindowsでUbuntuを使えるようにする理由はプログラミング環境の構築なので、VS Code(Visual Studio Code)が必須になるのでこれもインストールします。
まずはWindowsにインストール
WindowsにVS Codeをインストール。
Download for Windows→インストーラ(exeファイル)を起動してインストール

WindowsでVS Codeを開き、ExtensionsからRemote DevelopmentとWSLをインストール



VS Codeを閉じる
Ubuntuから開いてみる
Windows PowerShellを起動し、wslコマンドを実行するとUbuntuを操作できるようになる。そして、cdコマンドでUbuntuのホームディレクトリに移動できる。

※Windows PowerShellの背景色を変更したい場合はタイトルバーを右クリックしてプロパティから変更可能
適当なディレクトリを作成して、そのディレクトリをVS Codeで開いてみる。
#testという名前のディレクトリ作成
mkdir test
#testディレクトリが作成されたことを確認(現在のディレクトリに存在するファイルを確認)
ls
#testディレクトリに移動
cd test
#VS Codeを起動
code .

すると、VS Codeが起動する
対象ディレクトリも「TEST」となっている

以上。