[安装]

安装参考: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. 把dataframe 一列转成 array

    把dataframe 一列转成 array

  2. manim边学边做--角度标记

    manim中绘制一个角度其实就是绘制两条直线,本篇介绍的不是绘制角度,而是绘制角度标记. 对于锐角和钝角,角度标记是一个弧,弧的度数与角的度数一样: 对于直角,角度标记是一个垂直的拐角. manim中 ...

  3. 小tips:xml文件转为html表格展示示例

    books.xml文件格式如下: <?xml version="1.0" encoding="UTF-8"?> <xbrl xmlns=&qu ...

  4. CSS – vw, vh, position fixed and ICB (initial containing block)

    什么是 vw, vh? vh 的 v 指的是 viewport, h 就是 height. 它是 CSS 值的单位就像 px, %. .container { height: 30vh; backgr ...

  5. .NET 开源工业级移动端仓库管理系统

    前言 在工业生产中,定制化的软件对于每个环节都至关重要.对于仓库管理,推荐一款开源的仓库管理系统(WMS)解决方案. 这款基于.NET 框架开发的移动应用,提供了全面的仓库操作.订单处理.主数据管理. ...

  6. [Tkey] A decorative fence

    还是看看简单而富有美感的爆搜吧 #include<bits/stdc++.h> using namespace std; #define int long long #define tes ...

  7. Kubernetes ReplicaSet 控制器(十九)

    前面我们一起学习了 Pod 的原理和一些基本使用,但是在实际使用的时候并不会直接使用 Pod,而是会使用各种控制器来满足我们的需求,Kubernetes 中运行了一系列控制器来确保集群的当前状态与期望 ...

  8. Linux安装miniforge

    miniforge 安装 协议条款:bsd-3-clause 支持conda和mamba命令,两者效果一样,推荐使用mamba # Setup Miniforge wget "https:/ ...

  9. llama.cpp推理流程和常用函数介绍

    llama.cpp是一个高性能的CPU/GPU大语言模型推理框架,适用于消费级设备或边缘设备.开发者可以通过工具将各类开源大语言模型转换并量化成gguf格式的文件,然后通过llama.cpp实现本地推 ...

  10. vue 赶鸭子上架入门笔记(一) 安装开发环境

    准备接手一个 vue 的前端项目,从零开始学习 vue.目标不高大上,能看得懂代码,能进行简单的修改,改完能打包和部署. 首先解决 vue 开发环境的准备.访问 Node.js 官方网站,下载适合你操 ...