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?

More than 3 years have passed since last update.

WSL使ってWindowsにLinux環境構築してみた

Last updated at Posted at 2022-01-07

Windows上にLinux環境を構築する方法について説明します。

今回はWSLというLinux用 Windows サブシステムを利用します。

環境
OS: Windows 10 バージョン21H1

手順

  • WSLのインストール
  • Linux環境で使うユーザー名とパスワードを設定
  • Linuxパッケージの更新およびアップグレード

WSLのインストール

Windows PowerShellを【管理者】として実行します
poweshell run.png

起動したらコマンドwsl --installを実行します。
デフォルトではUbuntuがインストールされるので、それ以外をインストールしたい場合は
wsl --list --onlineコマンドを実行しインストール可能なディストリビューションを調べて
wsl --install -d Debianのように変更してインストールしてください。

PowerShell(Ubuntu以外を使いたい人向け)
PS C:\Windows\system32> wsl --list --online
インストールできる有効なディストリビューションの一覧を次に示します。
既定の分布は ' * ' で表されます。
 'wsl --install -d <Distro>'を使用してインストールします。

  NAME            FRIENDLY NAME
* Ubuntu          Ubuntu
  Debian          Debian GNU/Linux
  kali-linux      Kali Linux Rolling
  openSUSE-42     openSUSE Leap 42
  SLES-12         SUSE Linux Enterprise Server v12
  Ubuntu-16.04    Ubuntu 16.04 LTS
  Ubuntu-18.04    Ubuntu 18.04 LTS
  Ubuntu-20.04    Ubuntu 20.04 LTS

インストールコマンド実行

PowerShell
PS C:\Windows\system32> wsl --install
インストール中: 仮想マシン プラットフォーム
仮想マシン プラットフォーム はインストールされました。
インストール中: Linux 用 Windows サブシステム
Linux 用 Windows サブシステム はインストールされました。
ダウンロード中: WSL カーネル
インストール中: WSL カーネル
WSL カーネル はインストールされました。
ダウンロード中: Ubuntu
要求された操作は正常に終了しました。変更を有効にするには、システムを再起動する必要があります。
PS C:\Windows\system32>

インストールが完了したので、案内に従ってPCを再起動します。
再起動後にUbuntuのターミナルが立ち上がっていればWSLのインストールはOKです。
しかし、Ubuntuのインストールに失敗したようです。

Ubuntu
Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x80370102
Error: 0x80370102 ??????????????????????????????????????

こちらの記事を参考にBIOSで設定を変えれば大丈夫です。

BIOSで設定を変更してPC再起動後、スタートメニューからUbuntuを起動します。
するとインストールが正常に進みユーザー名の入力が求められます。
ubuntu installing.png

Linux環境で使うユーザー名とパスワードを設定します
ここで作成したユーザーはLinux 管理者と見なされ、sudo (Super User Do) 管理コマンドを実行できます。
今回はユーザー名をadminuserとしパスワードも入力すると以下のように進みます。

Ubuntu
Enter new UNIX username: adminuser
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sat Jan  8 04:06:04 JST 2022

  System load:  0.0                Processes:             8
  Usage of /:   0.4% of 250.98GB   Users logged in:       0
  Memory usage: 0%                 IPv4 address for eth0: 172.31.192.218
  Swap usage:   0%

0 updates can be installed immediately.
0 of these updates are security updates.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


This message is shown once once a day. To disable it please create the
/home/adminuser/.hushlogin file.
adminuser@DESKTOP-4AABD6F:~$

これでLinuxが使える状態になったのでUbuntuで優先パッケージ マネージャーを使用して、パッケージを更新およびアップグレードします。(Windowsでは自動更新がないため手動で定期更新が必要です)

Ubuntu
sudo apt update && sudo apt upgrade

これで環境構築は終了です

<参考記事>
WSL のインストール
【WSL2】wsl2のインストールで0x80370102 エラーが出たときの対処方法【HP】
WSL 開発環境を設定する

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?