Linux 用 Windows サブシステム [Windows 上の WSL 2 を使用して Linux をすばやく体験]

WSL の概要

WSL の正式名称は Windows Subsystem for Linux で、公式 Web サイトは次のように訳されます: Windows Subsystem for Linux (WSL)

公式ドキュメントへの直接アクセス: Windows Subsystem for Linux Documentation | Microsoft Docs

WSL1 と WSL2 の比較:
ここに画像の説明を挿入します

WSL2をインストールする

今回の設置環境は、

プロセッサー: Intel® Core™ i7-9750H CPU @ 2.60GHz 2.59 GHz
RAM: 16.0 GB (15.8 GB 利用可能)
システムタイプ: 64 ビット OS、x64 ベースのプロセッサー
オペレーティング システム: Windows 10 Professional

注: このインストールの前には、WSL と Ubuntu はインストールされていません。

インストールできるか確認してください

コンピュータは Hyper-V 仮想化をサポートする必要があります。Hyper
-V をサポートしているかどうかを確認するには、次の手順を実行します。

cmdを開いて入力しますsysteminfo

以下の図に示すように、Hyper-V 情報を確認すると、サポートされています。
ここに画像の説明を挿入します

インストール方法 1:

# 1.切换路径
cd D:\Linux\ubuntu20.04 
# 2.下载文件【时间较长】
Invoke-WebRequest -Uri https://wsldownload.azureedge.net/Ubuntu_2004.2020.424.0_x64.appx -OutFile Ubuntu20.04.appx -UseBasicParsing
# 3.
Rename-Item .\Ubuntu20.04.appx Ubuntu.zip
# 4. 
Expand-Archive .\Ubuntu.zip -Verbose 
# 5.
cd .\Ubuntu\ 
# 6.
.\ubuntu2004.exe

ここに画像の説明を挿入しますここに画像の説明を挿入します

インストール方法 2:

wsl --install
# –install 命令执行以下操作:
#    启用可选的 WSL 和虚拟机平台组件
#    下载并安装最新 Linux 内核
#    将 WSL 2 设置为默认值
#    下载并安装 Ubuntu Linux 发行版(可能需要重新启动),默认是安装在 C 盘的(如果要安装其他盘可以看下面的操作)
# 注意:上述命令仅在完全未安装 WSL 时才有效,如果运行 wsl --install 并查看 WSL 帮助文本,
# 请尝试运行 wsl --list --online 以查看可用发行版列表并运行 wsl --install -d以安装发行版。
wsl --list --online
wsl --install -d Ubuntu-20.04
# 查看版本
wsl -l -v 

ミラーソースを更新する

# 进入linux终端执行
sudo vim /etc/apt/sources.list

注:ファイルを入力するには
Enter を入力し、ファイルを保存して終了するには Enter を入力します。キーを押すとファイル編集モードに入り、 キーを押すとファイル編集モードが終了します。vim file:wq
iesc

公式ソースをコメントアウトし、次の 2 つのいずれかに置き換えます (私のものは Ubuntu20.04 です。他のバージョンやソースは自分でオンラインで検索できます)

# 阿里云
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

# 清华
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

wsl サブシステムをアンインストールする

# 首先查看本机安装了哪些子系统:
wsl --list --all
# unregister 注销
wsl --unregister <System_name>

そのパスに移動してすべてのファイルを削除するだけです。
ここに画像の説明を挿入します

Windows ターミナルをインストールする

Windows ターミナルは、コマンド ライン ツール、PowerShell、WSL、その他のシェル ユーザー ツールの管理に役立ち、最高の WSL エクスペリエンスを提供します。ダウンロード アドレス
をクリックしてダウンロードするか、Microsoft ストア (Microsoft ストア) にアクセスして Windows ターミナルというキーワードを見つけます。また、Microsoft App Store を開いて「ターミナル」を検索し、インストールすることもできます。ターミナル インターフェイスは次のとおりです。


ここに画像の説明を挿入します

Ubuntuターミナルを開く

ここに画像の説明を挿入します

oh-my-zshをインストールする

ubuntu のターミナルで実行します。

# 1.安装 zsh:
sudo apt update 
sudo apt install git zsh -y
chsh -s /bin/zsh
# 2.安装oh my zsh所需的字体
git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh
# 3.安装oh my zsh
cd ../
wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh  # 国内下载地址
# 3.1 给 install.sh 添加执行权限
chmod +x install.sh
# 3.2 修改 install.sh 的镜像
vi install.sh
#将以下
#		REPO=${REPO:-ohmyzsh/ohmyzsh}
#		REMOTE=${REMOTE:-https://github.com/${REPO}.git}
#更改为
#		REPO=${REPO:-mirrors/oh-my-zsh}
#		REMOTE=${REMOTE:-https://gitee.com/${REPO}.git}
# 3.3 保存退出,执行 
./install.sh 

# 4.安装皮肤
vi ~/.oh-my-zsh/themes/agnoster.zsh-theme
#把 92 行修改为:
#		prompt_segment green black "%(!.%{%F{yellow}%}.)%n"

# 5.安装历史命令自动补全 & 高亮显示
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
# 5.1 安装完改一下配置文件
vim ~/.zshrc
# 5.2 把plugins中两个刚刚下载好的插件名字加进去(73行),然后保存退出
#		plugins=(git zsh-autosuggestions zsh-syntax-highlighting )
# 5.3 最后更新一下配置文件
source .zshrc

参考文献:

Windows で WSL 2 を使用して、スムーズな Linux をすぐに体験する方法

おすすめ

転載: blog.csdn.net/qq_41361442/article/details/131704180