[安装]

安装参考: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. 使用 `Roslyn` 分析器和修复器对.cs源代码添加头部注释

    之前写过两篇关于Roslyn源生成器生成源代码的用例,今天使用Roslyn的代码修复器CodeFixProvider实现一个cs文件头部注释的功能, 代码修复器会同时涉及到CodeFixProvide ...

  2. 修改SpringBoot的配置文件application.yaml后启动失败

    经常碰到修改application.yaml文件之后,SpringBoot项目启动失败的,报错信息如下 Connected to the target VM, address: '127.0.0.1: ...

  3. vue单元测试

    0.测试钩子函数 describe的钩子函数 在测试块describe中,存在这四个钩子函数,他会在describe执行的不同时期调用: before():在该区块的所有测试用例之前执行 after( ...

  4. JavaScript习题之判断题

    1. JavaScript是Java语言的脚本形式.( ) 2. JavaScript中的方法名不区分大小写.( ) 3. JavaScript语句结束时的分号可以省略.( ) 4. 通过外链式引入J ...

  5. Flutter(able) 的单例模式

    文/ 杨加康,CFUG 社区成员,<Flutter 开发之旅从南到北>作者,小米工程师 单例设计模式(Singleton Design Pattern)理解起来非常简单. 一个类只允许创建 ...

  6. 如何更改Wordpress语言为中文

    在使用WordPress的时候,一般安装默认语言是英文,可以在后台设置里面直接修改站点语言为简体中文,当后台没有语言选项框的这一栏,如下图所示,该怎么办呢? 这个时候我们可以找到文件wp-config ...

  7. LeetCode 1000. Minimum Cost to Merge Stones (区间 DP)

    根据寒神题解 https://leetcode.com/problems/minimum-cost-to-merge-stones/discuss/247567/JavaC%2B%2BPython-D ...

  8. 全网最适合入门的面向对象编程教程:55 Python字符串与序列化-字节序列类型和可变字节字符串

    全网最适合入门的面向对象编程教程:55 Python 字符串与序列化-字节序列类型和可变字节字符串 摘要: 在 Python 中,字符编码是将字符映射为字节的过程,而字节序列(bytes)则是存储这些 ...

  9. 简化部署流程:Rainbond让Jeepay支付系统部署更轻松

    在如今的开发环境中,部署一套像 Jeepay 这样的 Java 支付系统往往需要开发者面对繁琐的配置.依赖环境管理以及服务的高可用性保障,手动部署和运维变得异常艰巨和费时.然而,借助 Rainbond ...

  10. vue 中 slot 的使用方式,以及作用域插槽的用法

    分类:插槽又分为匿名插槽.具名插槽以及作用域插槽 : 匿名插槽,我们又可以叫它单个插槽或者默认插槽 因为组件标签中间是不允许写内容的,但是可以插入 插槽 :template 标签 : 插槽的使用方法 ...