[安装]

安装参考: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. [学习笔记] 2-SAT

    引入 有 \(n\) 个变量 \(x_1 \cdots x_n\),每个变量的取值范围为 \(\{0,1\}\),另有 \(m\) 个条件,每个条件都是对其中两个变量的取值限制,形如要么 \(x_i ...

  2. JAVAEE——maven安装

    一.安装本地Maven 注意:检查JAVA_HOME环境变量, maven本身就是java写的,所以要求必须先安装JDK,检查本机jak环境win+r后输入cmd,然后输入java -version, ...

  3. 使用BAT脚本实现文件异机备份,并且还有文件的时间戳

    事件起因: 由于我们单位是创意设计公司,在设计文件的隐私性和保密性上都是有要求的,单位里的办公机的USB口都是禁用的,防治资料泄露:服务器之间还要做实时备份,并且文件的创建时间都是要保证准确性的.但是 ...

  4. PasteForm最佳CRUD实践,实际案例PasteTemplate详解之3000问(二)

    作为"贴代码"力推的一个CRUD实践项目PasteTemplate,在对现有的3个项目进行实战后效果非常舒服!下面就针对PasteForm为啥我愿称为最佳CRUD做一些回答: 哪里 ...

  5. npm/yarn是什么,他们的区别 ? & node.js 又是个啥

    是什么? npm(全称Node Package Manager,即 node 包管理器) ,是Node.js默认的包管理系统 ; 区别: yarn 的速度开快,因为yarn 是并行安装,npm是串行安 ...

  6. 怎么封装一个vue的自定义指令

    自定义指令分为 全局和局部的指令 : 1. 自定义全局指令: 在 mian.js 中 ,使用 Vue.directive('指令名' ,  配置对象 ) 2. 局部自定义指令 在组件中使用 direc ...

  7. 24. echarts 可以画哪些图表

    1. 折线图 2. 柱状图 3. 饼图 4. 地图 5. 雷达图 延申问题:画折线图和柱状图哪些配置可以改变样式 1.  color  设置每个数据的颜色 2. grid 网格设置图表的大小 3. s ...

  8. day05-JDK的卸载与安装

    JDK卸载 右键我的电脑--属性--高级系统设置--环境变量,找到JAVA_HOME安装目录,删除Java安装目录 删除JAVA_HOME 删除path下关于java的目录 cmd查看Java -ve ...

  9. SQL注入利用及绕过总结

    SQL注入及绕过姿势总结 概述 SQL注入指用户输入的参数可控且没有被过滤,攻击者输入的恶意代码被传到后端与SQL语句一起构造并在数据库中执行 不同数据库的语法可能存在差异,以MySQL为例,其他差异 ...

  10. Kubernetes 集群中 Ingress 故障的根因诊断

    作者:scwang18,主要负责技术架构,在容器云方向颇有研究. 前言 KubeSphere 是青云开源的基于 Kubernetes 的云原生分布式操作系统,提供了比较炫酷的 Kubernetes 集 ...