windows10 安裝wsl2

0 必须先启用“适用于 Linux 的 Windows 子系统”可选功能,然后才能在 Windows 上安装 Linux 分发版。 以管理员身份打开 PowerShell 并运行

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

1 下载wsl
image

wsl --install

2 下好后重启电脑, 我的重启后就自动帮我下了
image

如果没有自动下载

wsl --install -d ubuntu

设置用户名密码
4 更新

sudo apt update
sudo apt upgrade

按Y确认
5 安装Windows Terminal Preview
Windows Terminal Preview

sudo apt install wslu

sslfetch

image
6 在VScode上使用
在VScode下安装插件
image

在wsl2中(当然也可以在VScode中打开终端)
下载nodejs

sudo apt-get install nodejs

sudo apt install npm

创建一个文件夹

mkdir serverexample/

cd serverexample/

打开VScode(注意中间有个空格)

code .

就可以用VScode创建文件了

创建一个网页
在刚才的文件夹下创建 package.json

{

"name": "Demo",

"version": "1.0.0",

"description": "demo project.",

"scripts": {

"lite": "lite-server --port 10001",

"start": "npm run lite"

},

"author": "",

"license": "ISC",

"devDependencies": {

"lite-server": "^1.3.1"

}

}

再创建一个 index.html

<h1>Hello World<h1>

然后输入命令创建网页

npm install

打开网页

npm star

image

posted @ 2023-04-15 17:20  无形深空  阅读(176)  评论(0编辑  收藏  举报