[安装]

安装参考:https://learn.microsoft.com/zh-cn/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package

wsl分为两个版本: V1 和 V2

如果想要从V1升级到V2,则需要

1.开启虚拟化, 查看是否开启

任务管理器 > 性能 > CPU, 查看虚拟化

系统安装完成之后, 子系统是使用的ubuntu系统,首先都会进行软件包的更新操作

1.

sudo apt update

2.更换软件源,进行加速

1.备份官方镜像源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup 2.更换镜像源

/etc/apt/sources.list
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

3.更新
apt update

镜像源:

阿里:
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse 中科大
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse 网易
deb http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse

使用x-shell连接子系统

https://blog.csdn.net/weixin_43647393/article/details/116013953

示例:

1.安装Java

1.查看是否已存在Java
java -version
Command 'java' not found, but can be installed with: apt install default-jre
apt install openjdk-11-jre-headless
apt install openjdk-8-jre-headless
apt install openjdk-9-jre-headless 2.不存在则安装
apt install default-jre

2.安装Python3 + Python2

python3:
1.
sudo apt update 2.
apt install python3-pip python2:
1.默认存储库不包含 Python2 的 pip。因此,要在您的系统上使用它,请启用“universe”存储库。
add-apt-repository universe 2.
apt install python2 3.下载Python2 pip脚本
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py 4.安装
sudo python2 get-pip.py

3.安装Nginx

# nginx: apt install nginx
配置文件: /etc/nginx (虚拟主机配置文件存储在/etc/nginx/sites-available目录。仅当链接到/etc/nginx/sites-enabled目录时,Nginx才会使用此目录中的配置文件), 一般直接将域名配置文件放到config.d目录下
日志目录:/var/log/nginx
默认项目目录:/var/www/html
参考: https://www.myfreax.com/how-to-install-nginx-on-ubuntu-22-04/

4.安装MySQL8

# mysql:
apt install mysql-server
/etc/init.d/mysql start/restart/status 服务配置文件:vim /etc/mysql/mysql.conf.d/mysqld.cnf

安装其他版本:

例如: 5.7

apt install mysql-server-5.7

5.安装PHP

# PHP
apt install php-fpm
/etc/init.d/php8.1-fpm start/restart 扩展安装
apt install php8.1-mysql php8.1-gd php8.1-zip  php8.1-xml nginx与PHP配合使用:
server {
server_name demo.com;
root /var/www/demo/;
index index.php index.html; access_log /var/log/nginx/demo.com.access.log;
error_log /var/log/nginx/demo.com.error.log notice; location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
}

注意:
在Windows的vhost文件中添加域名映射 127.0.0.1 demo.com

更多参考安装:
apt install -y php8.2-cli php8.2-dev  php8.2-pgsql php8.2-sqlite3 php8.2-gd  php8.2-curl  php8.2-imap \
php8.2-mysql php8.2-mbstring  php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap   php8.2-intl php8.2-readline \
php8.2-ldap  php8.2-msgpack php8.2-igbinary php8.2-redis php8.2-swoole  php8.2-memcached php8.2-pcov \
php8.2-fpm php8.2-gmp php8.2-imagick php8.2-mcrypt php8.2-uuid php8.2-yaml

安装其他版本PHP,例如php7.4

add-apt-repository ppa:ondrej/php
apt update
apt install php7.4 php7.4-fpm php7.4-bcmath php7.4-curl php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-xml php7.4-zip php7.4-redis



php.7.2

apt install php7.2 php7.2-mysql php7.2-fpm php7.2-curl php7.2-xml php7.2-gd php7.2-mbstring php-memcached php7.2-zip


常见问题:

无法启动php-fpm, 查看/usr/sbin/php-fpm没有安装成功, 重新安装发现错误:

You are seeing this message because you have apache2 package installed.

解决: 原因是已经安装了apache2的包, 所以为了后面使用NGINX,即卸载apache2

apt-get purge apache2

apt autoremove

apt autoclean

然后重新安装php-fpm即可

6.安装composer

wget https://getcomposer.org/composer.phar

mv composer.phar composer

chmod +x composer

mv composer /usr/local/bin/

# 加速
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 去除使用root执行命令的提示

vim /etc/environment
文字
export COMPOSER_ALLOW_SUPERUSER=1

source /etc/environment

7.安装Redis5

apt install redis

# 配置文件
/etc/redis/redis.conf # 启动
/etc/init.d/redis-server start

下载内核更新包:

根据自己的系统选择:
x64:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
arm64:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_arm64.msi

8.安装docker

1)更新源

$ sudo vim /etc/apt/sources.list
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse

2)卸载老版本

sudo apt-get remove docker docker-engine docker.io

3)安装

a.安装系统工具
$ sudo apt-get update
$ sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common b.安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - c.写入软件源信息
$ sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" d.更新并安装Docker-CE
$ sudo apt-get -y update
$ sudo apt-get -y install docker-ce # 安装指定版本
# Step 1: 查找Docker-CE的版本:
$ apt-cache madison docker-ce
docker-ce | 17.03.1~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.03.0~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages # Step 2: 安装指定版本的Docker-CE: (VERSION 如上 17.03.1~ce-0~ubuntu-xenial)
$ sudo apt-get -y install docker-ce=[VERSION]

4)镜像加速

$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://irnlfwui.mirror.aliyuncs.com"]
}
EOF $ sudo systemctl daemon-reload
$ sudo systemctl restart docker

5)验证

$ sudo docker --version
Docker version 17.12.1-ce, build 7390fc6 $ sudo docker version
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:17:40 2018
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.1-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:16:13 2018
OS/Arch: linux/amd64
Experimental: false $ sudo docker info
Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 6
...

注意点:

1.这里可能会启动发生错误, 显示systemctl无法使用, 只能使用service的命令方式

2.启动成功, 但是查看状态却是失败的, 查看日志 tail /var/log/docker.log

G: Module nf_nat not found in directory /lib/modules/4.4.0-19041-Microsoft`, error: exit status 1"
time="2023-07-13T14:11:42.815141600+08:00" level=warning msg="Running modprobe xt_conntrack failed with message: `modprobe: WARNING: Module xt_conntrack not found in directory /lib/modules/4.4.0-19041-Microsoft`, error: exit status 1"
Error starting daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.6.1: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
(exit status 3)

  解决:

1.禁用iptables
dockerd --iptables=false

2.使用管理员身份打开Ubuntu. 重点!!!  重新执行启动docker服务即可

9, 安装nodejs

NodeSource提供的官方包)

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

apt)

sudo apt update
sudo apt install nodejs
#不自带 npm 需要自行安装
sudo apt install npm
# 升级 npm
sudo npm install npm -g # 使用n进行版本管理
sudo npm install n -g
# 下载最新稳定版
sudo n stable
# 下载最新版
sudo n lastest
# 查看已下载的版本
sudo n ls
# 切换 Node 版本
sudo n 18.21.1

常用命令:

1.查看已经安装的分发版本
wsl --list --all 2.查看正在运行的版本
wls --list --all 3.删除指定版本
wls --unregister <版本名称>

4.升级版本

wsl --set-version Ubuntu 2

 5.查看在线可使用版本

wsl --list --online

ubuntu中查看wsl版本:   cat /proc/sys/kernel/osrelease

5.10.16.3-microsoft-standard-WSL2   // 是wsl2版本

常见问题:

1. pkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem”

apt-get install 报错

解决:

1.切换目录
cd /var/lib/dpkg/updates 2.删除目录下文件
rm -rf * 3.升级
sudo apt-get upgrade 4.再更新
sudo apt-get update

2. 在使用webpack-dev-server启动本地服务的时候, 由于项目是放到Windows下的, 但是在wls中运行vue项目(由于npm版本在Windows下安装依赖有问题), 导致无法修改之后热加载

解决:

1) 将项目放到非windows下, 也就是不要运行项目在/mnt/c|d|e磁盘上, 可以将项目放到Linux系统目录下, 例如:/usr/local/www/
这样再启动就不会有问题了 2)在运行npm run dev之前,设置环境变量
export CHOKIDAR_USEPOLLING=true
或者将这个命令放到.env文件中

Windows之子系统WSL的更多相关文章

  1. 如何重启 Windows 10 子系统(WSL) ubuntu

    如何重启 Windows 10 子系统(WSL) ubuntu WSL 子系统是基于 LxssManager 服务运行的. 只需要将 LxssManager 重启即可. 可以做成一个 bat 文件. ...

  2. .NET Core多平台开发体验[3]: Linux (Windows Linux子系统)

    如果想体验Linux环境下开发和运行.NET Core应用,我们有多种选择.一种就是在一台物理机上安装原生的Linux,我们可以根据自身的喜好选择某种Linux Distribution,目前来说像R ...

  3. Linux (Windows Linux子系统)

    Linux (Windows Linux子系统) 如果想体验Linux环境下开发和运行.NET Core应用,我们有多种选择.一种就是在一台物理机上安装原生的Linux,我们可以根据自身的喜好选择某种 ...

  4. windows linux 子系统及windows terminal的使用。

    windows linux 子系统及windows terminal的使用. windows linux (wsl) 其实windows早就为我们准备好了子系统,但是我们的应用商店经常挂掉.因此都用不 ...

  5. Windows 10 子系统 Ubuntu 中安装 FastAdmin

    Windows 10 子系统 Ubuntu 中安装 FastAdmin 打开 Windows 10 子系统 安装 Ubuntu 修改安装源为阿里的 %LOCALAPPDATA%\Packages\Ca ...

  6. 黑科技抢先尝(续) - Windows terminal中WSL Linux 终端的极简美化指南

    目录 修改默认源,为apt-get安装提速 安装python 和 python pip 安装 zsh 安装powerline-font中的特定字体 安装powerline-shell 修改~目录下的配 ...

  7. windows如何访问wsl系统下的文件

    windows如何访问wsl系统下的文件 可以在wsl终端输入以下命令 explorer.exe . 会出现如下界面 这样就可以很方便的查看wsl的文件了

  8. Windows 10 之 WSL 2

    Windows Subsystem for Linux(WSL)无疑大大提升了Windows下程序开发的体验. WSL 2向开发者提供的完整的系统调用兼容,使得许多无法在WSL 1中安装的应用,如Do ...

  9. Windows Sublime Text 配置Linux子系统(WSL)下的 gcc/g++ 编译环境

    0. 简介(若已了解背景可以跳过此部分) Windows 10 Build 14316以上版本中加入了"Windows系统的Linux子系统"(Windows Subsystem ...

  10. windows10 ubuntu子系统 WSL文件位置

    windows10 的linux子系统(windows subsystem for linux)WSL 文件位置 以我的系统为例,WSL的root目录对应windows的: C:\Users\xiao ...

随机推荐

  1. 开源文档管理系统 MinDoc 安装和使用教程

    说到文档管理,很多团队的文档管理都是一团糟,每个员工在自己本地写了各种 Word 文档.Excel 表格.甚至还有手写的便签,到处都是,找起来就像大海捞针.有些聪明的团队开始用飞书来管理团队文档,但是 ...

  2. Unity 刚体 AddForce 的几种力类型

    今天在实现 2D 横版跳跃的时候,发现使用AddForce添加的力太突兀了,没有逐渐向上的过程,发现AddForce还有ForceMode mode参数 以下部分内容摘自Bing Copilot总结 ...

  3. DOM & BOM – 冷知识 (新手)

    JS 无法 query select 到伪元素 参考: 使用JS控制伪元素的几种方法 JS style remove property 是 kebab-case set property 是 came ...

  4. Java Web 拾遗

    许是年纪大了,老是回忆起以前的点点滴滴.翻看当初的代码,如同偶遇多年未见的前女友,曾经一起深入交流的情谊在颔首之间消散,令人烦躁. 今天就来聊聊老生常谈的 Java Web 开发.缘于一个简单的Spr ...

  5. logisim学习感想(持续更新)

    状态机类型 存在两种类型的状态机,分别为mealy型状态机和moore型状态机,在实验中,二者的大体实现如下: 其中从输入到输出的连线只有mealy状态机才有,而moore型则无此线. 区分两种类型的 ...

  6. 第44天:WEB攻防-PHP应用&SQL盲注&布尔回显&延时判断&报错处理&增删改查方式

    #PHP-MYSQL-SQL操作-增删改查 1.功能:数据查询 查询:SELECT * FROM news where id=$id 2.功能:新增用户,添加新闻等 增加:INSERT INTO ne ...

  7. 数组 Array 的属性 和 方法总结

    1. Array 的属性 2. Array 的方法 2.1 增加数组单元 参数一半都是数组单元 a)unshift 方法 在数组的最前面添加数组元素 <script> const arr ...

  8. Vue 如何实现组件切换的时候,让组件缓存,不会被销毁

    使用场景:我们开发项目的时候,会遇到组件之间的切换,一般都是创建组件销毁组件来回切换 :但是现在需求是切换组件的时候,另一个组件不会销毁: 基于这个需求 ,我们使用 keep-live 组件包裹起来要 ...

  9. 云原生周刊:KubeCon China 2023 详细议程公布 | 2023.8.7

    开源项目推荐 Spiderpool Spiderpool 是一个 Kubernetes 底层网络解决方案.它提供丰富的 IPAM 功能和 CNI 集成能力,为开源社区的 CNI 项目提供支持,允许多个 ...

  10. 我的博客网站为什么又回归Blazor了

    引言 在博客网站的开发征程中,站长可谓是一路披荆斩棘.从最初的构思到实践,先后涉足了多种开发技术,包括 [MVC](ASP.NET Core MVC 概述 | Microsoft Learn).[Ra ...