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?

WSL環境を切り替える

Last updated at Posted at 2025-05-06

環境作成

管理者としてPowershellを開く

以下のコマンドで既存のWSL環境をエクスポート

wsl --export Ubuntu Ubuntu.tar

エクスポートしたファイルを使用して、今回は授業用の環境を作成

wsl --import UbuntuClass C:\Users\ユーザー名\wsl\UbuntuClass Ubuntu.tar

インポート先のディレクトリはシステムディレクトリ以外ならどこでもいい

最後に

wsl --list --all

で作成した環境があるか確認してください

環境切り替え

いつもどうりpowershellなどを開いて上の↓をおすと先ほど作成した環境があると思うのでそれを、右クリック

わかりやすいようにユーザー名を変えておきましょう
rootユーザーで作業します

sudo usermod -l 新しいユーザー名 -d /home/新しいユーザー名 -m 旧ユーザー名

追加した環境はあくまで元の環境のコピーなので元の環境は変わりません

再度環境を開いたときrootユーザでログインしてしまう状態なので通常ユーザでログインにします。

作成した環境内で/etc/wsl.confを編集します

sudo nano /etc/wsl.conf

以下の内容を追加します

[user]
default=最初に起動したいユーザ名

最後にpowershellから以下のコマンド入力し再起動します

wsl --terminate UbuntuClass

その他

もし環境が不要になったら

wsl --unregister UbuntuClass

で削除できます。

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?