安裝wsl2
先決條件
必須運行 Windows 10 版本 2004 及更高版本(內部版本 19041 及更高版本)
請參閱[官方文檔](安裝 WSL | Microsoft Learn
安裝
wsl --install
定制安裝linux發行版
默認情況下,安裝的 Linux 分發版為 Ubuntu。 可以使用 -d 標志進行更改。
若要更改安裝的發行版,請輸入:wsl --install -d <Distribution Name>。 將 <Distribution Name> 替換為要安裝的發行版的名稱。
-
若要查看可通過在線商店下載的可用 Linux 發行版列表,請輸入:wsl --list --online 或 wsl -l -o。
image.png 若要在初始安裝后安裝其他 Linux 發行版,還可使用命令:wsl --install -d <Distribution Name>。
我直接用下面命令安裝的
wsl --install -d Ubuntu-22.04
期間需要輸入ubuntu的賬號和密碼,安裝完后需要重啟
更換apt清華源
cd /etc/apt
cp sources.list sources.list.bak //備份原始文件
sudo vi sources.list // 編輯文件,全部替換
替換內容如下我這里使用的清華源ubuntu | 鏡像站使用幫助 | 清華大學開源軟件鏡像站 | Tsinghua Open Source Mirror,也可以使用其他國內源
# 默認注釋了源碼鏡像以提高 apt update 速度,如有需要可自行取消注釋
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 預發布軟件源,不建議啟用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
替換后重新打開windows 終端并跟新ubuntu
// 更新ubuntu
sudo apt update && sudo apt upgrade
安裝zsh和ohmyzsh
sudo apt install zsh
// 比較慢,耐心等,有可能中斷,多試幾次,也可以用curl 或者 fetch
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
安裝 Docker Desktop
先開啟hyper-v,勾選確定,重啟
開始安裝docker
下載 Docker Desktop 并按照安裝說明進行操作。
-
安裝后,從 Windows 開始菜單啟動 Docker Desktop,然后從任務欄的隱藏圖標菜單中選擇 Docker 圖標。 右鍵單擊該圖標以顯示 Docker 命令菜單,然后選擇“設置”。
image.png
-
確保在“設置”>“常規”中選中“使用基于 WSL 2 的引擎”。image.png
-
通過轉到“設置”>“資源”>“WSL 集成”,從要啟用 Docker 集成的已安裝 WSL 2 發行版中進行選擇。image.png
若要確認已安裝 Docker,請打開 WSL 發行版(例如 Ubuntu),并通過輸入
docker --version
來顯示版本和內部版本號-
通過使用
docker run hello-world
運行簡單的內置 Docker 映像,測試安裝是否正常工作
image.png
安裝node環境
安裝nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
github上的, 網絡原因,需要等很久或者多次重試, 推薦用下面的國內安裝工具
nvm-cn: ?? nvm國內安裝工具 (gitee.com)
bash -c "$(curl -fsSL https://gitee.com/RubyKids/nvm-cn/raw/main/install.sh)"
與windows的node環境沖突解決
where node
/home/用戶名/.nvm/versions/node/v18.15.0/bin/node
sudo vim ~/.zshrc
# 在末尾加上
export NODE_HOME=/home/用戶名/.nvm/versions/node/v18.15.0 //此處用上面where node顯示的路徑,到bin前面
export PATH=$NODE_HOME/bin:$PATH