WSL 安装 Ubuntu

WSL 安装 Ubuntu

系统使用windows 11

启用 Windows 虚拟化和 Linux 子系统功能

  • 打开 “启用或关闭 Windows功能”,找到并勾选以下选项 (完成后需重启):
    • Virtual Machine Platform
    • Hyper-V
    • 适用于 Linux 的 Windows 子系统

更新 WSL

打开终端,输入更新命令:

wsl --install -d Ubuntu 
如果是第一次使用 wsl,可能会下载 wsl 安装包,使用命令行的方式下载速度可能很慢,可以点击这里 手动下载 WSL 离线包并安装。

安装 Ubuntu 22.04

在终端中输入命令:

wsl --install -d Ubuntu-22.04 

等待下载并安装,安装完毕后要求输入 Ubuntu 的用户名和密码。

更换软件源

  • sudo nano /etc/apt/sources.list
  • 替换为阿里源
  • 操作方法:
    • 按下 Alt + \ 将光标移动到文件开头
    • 按下 Alt + A 设置锚点
    • 按下 Alt + / 将光标移动到文件结尾
    • Ctrl + K(剪切) 或 Alt + D(直接删除)
    • 复制阿里安装源
    • 鼠标右键单击粘贴在 nano 中

22.04 阿里源:

deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse # deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse 

更新系统

sudoapt update sudoapt upgrade 

文件互传

文件管理器左侧边栏下部:Linux

在这里插入图片描述


如果你已经进入 WSL,可以用:

cp /mnt/c/path/to/file ~/destination/ mv /mnt/c/path/to/file ~/destination/ 

wsl 常用命令

  • wsl --update 这个命令只是更新 WSL 内核和相关组件(比如 WSLg、系统支持文件),并不会自动安装或更新 Ubuntu 发行版。
  • wsl --list --online 查看 WSL 当前支持、可以直接安装的 Linux 发行版列表
  • wsl --list --verbose 查看已安装
  • wsl --set-default-version 2 :默认安装到 wsl2
  • wsl -d Ubuntu-22.04 启动指定的 Ubuntu
  • wsl --unregister Ubuntu-20.04:卸载
  • wsl --shutdown:重启wsl

wsl --install -d Ubuntu 默认安装最新的

# 安装 Ubuntu 22.04 wsl --install -d Ubuntu-22.04 # 安装 Ubuntu 20.04 wsl --install -d Ubuntu-20.04 # 安装 Ubuntu 18.04 wsl --install -d Ubuntu-18.04 # 安装 Ubuntu 16.04 微软已经下架了这个旧版本 wsl --install -d Ubuntu-16.04 ``` 

vscode 远程连接

vscode 中搜索 WSL 扩展,安装完毕后按下图查看 Ubuntu 系统:

在这里插入图片描述


点击 Ubuntu -22.04 右侧的箭头,连接到 Ubuntu :

在这里插入图片描述

wsl 踩坑

无法访问外网:wsl setting - 网络 - 网络模式 - Mirrored(镜像模式)

在镜像模式下,wsl 会复制主机的网络接口,如果是单网卡多 IP ,则 Ubuntu 默认使用那个配置了路由的网段 IP。

在这里插入图片描述

设置开发环境

本地编译

本地编译需要安装开发工具和必要的库。需要安装以下包:

 $ sudoapt update $ sudoaptinstallgawkwgetgit diffstat unzip texinfo \ gcc-multilib build-essential chrpath socat libsdl1.2-dev \ xterm ncurses-dev lzop libelf-dev 

交叉编译

32 位 ARM 交叉编译器和工具链
sudoaptinstall gcc-arm-linux-gnueabihf binutils-arm-linux-gnueabihf 
如果安装软件浮点数版本,将 gnueabihf 改为 gnueabi
64 位 ARM 交叉编译器和工具链
sudoaptinstall gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu 
指定编译器版本

上面的命令是安装 Ubuntu 发行版支持的最新版本,如果要指定特定的编译器版本,使用:gcc-<version>-<arch>-linux-gnu* ,其中 version 是一个数字,代表 gcc 的版本。比如安装 GCC8,可以使用:

sudoaptinstall gcc-8-aarch64-linux-gnu 

下载 Linux 源码

下载最新源码

使用下列命令下载最新的 Linux 源码,这里使用 depth=1 来避免下载历史记录(几个 GB大小),只是选择上一次提交的历史记录(2025.11 月大约 270 MB):

git clone https://github.com/torvalds/linux --depth=1

或者:

git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --depth=1
github 站点和 kernel.org 站点是官方下载站点,但在国内的速度都相当慢,还存在下载一半失败的现象。这里推荐国内的镜像站点(码云,每日同步):

下载指定版本

上述是克隆最新的 Linux 代码,大部分时候我们需要指定的版本,比如克隆 v5.10 版本。有两种方法:

克隆指定的版本(只含该版本对应的一个 commit)

git clone --depth=1 --branch=v5.10 https://github.com/torvalds/linux 

完整克隆,然后 checkout :

git clone https://github.com/torvalds/linux git checkout v5.10 

其它 Ubuntu 版本的安装源(阿里源)

Ubuntu 24.04

deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse # deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse 

Ubuntu 20.04

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse # deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse 

Ubuntu 18.04

deb https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse # deb https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse 

Read more

Python 简介与入门

一、Python 是什么 Python 是一门解释型、面向对象、跨平台的通用编程语言,由吉多・范罗苏姆于 1991 年发布。它以简洁易读、语法优雅为核心特点,摒弃了 C/C++、Java 等语言繁琐的语法规则,让开发者能更专注于业务逻辑本身,而非代码格式,是编程入门的首选语言,也被广泛应用于各类工程开发场景。 简单来说,Python 能帮我们实现工作自动化(如文件批量处理、数据自动整理)、软件开发(如网站、小游戏、GUI 程序),还能解决专业开发中 “编译 - 测试” 周期长的问题,是兼顾入门友好和工业级应用的编程语言。 二、Python 的核心优势 1. 易上手,可读性强:语法接近自然语言,新手能快速入门,代码书写规范统一,团队协作时易读易维护。 2. 功能强大,

By Ne0inhk

Python 数据分析第三版(一)

原文:annas-archive.org/md5/74a7b24994c40ad3a90c290c07b529df 译者:飞龙 协议:CC BY-NC-SA 4.0 序言 数据分析使你能够通过发现新的模式和趋势,从大数据和小数据中创造价值,而 Python 是分析各种数据的最受欢迎工具之一。本书将带你快速入门 Python 数据分析,探索数据分析中的不同阶段和方法论,并学习如何使用 Python 生态系统中的现代库来创建高效的数据管道。 本书从使用 Python 进行基本统计和数据分析入手,你将通过简单易懂的示例进行复杂的数据分析与建模、数据处理、数据清理和数据可视化。接着,你将学习如何使用 ARMA 模型进行时间序列分析和信号处理。随着深入学习,你还将掌握如何使用机器学习算法(如回归、分类、主成分分析(PCA)和聚类)进行智能处理和数据分析。在最后几章中,你将通过实际案例分析文本数据和图像数据,分别使用自然语言处理(NLP)和图像分析技术。最后,本书还将展示如何使用

By Ne0inhk

Windows上安装 Python 环境并配置环境变量 (超详细教程)

‌一、下载 Python 安装包‌ 1. ‌选择版本‌ * 推荐选择最新稳定版(如 ‌Python 3.12.x‌),点击 Download Windows installer (64-bit)(64位系统)或 Download Windows installer (32-bit)(32位系统)。 * 如果不确定系统位数,按 Win + Pause 打开系统信息,查看 ‌系统类型‌。 ‌访问官网‌ 打开浏览器,进入 Python 官方下载页面:https://www.python.org/downloads/windows/ ‌二、安装 Python‌ 1. ‌运行安装程序‌ 双击下载的 .exe 文件(

By Ne0inhk
响应速度拉满!手把手教你自制 FPS 级虚拟键盘 (Flutter + Python + UDP 深度实战),深夜算竞助手

响应速度拉满!手把手教你自制 FPS 级虚拟键盘 (Flutter + Python + UDP 深度实战),深夜算竞助手

响应速度拉满!手把手教你自制高性能 FPS 级虚拟键盘 (Flutter + Python + UDP) 你在宿舍敲代码的时候是否感觉到键盘声音太大影响室友,图书馆时,需要敲键盘但是又怕影响到其他人,想玩一些一般的FPS游戏又没有带键盘 ,而市面上的模拟键盘产品要么效果差要么需要收费,本篇就是一个完全免费开源的解决这个问题的项目,可以直接将项目安装包安装在你的安卓设备上,便可以使用高性能虚拟键盘 Github(“https://github.com/MoonPointer-Byte/MoonKeyboard”) 1. 引言:为什么要自制虚拟键盘? 在远程控制、多端协同或 FPS 游戏场景中,我们经常需要一个能自定义按键布局、且响应极快的虚拟键盘。市面上的远程输入软件通常存在两个问题: 1. 延迟高:基于 TCP 或 HTTP 的传输在高频操作下有明显的滞后感。 2. 游戏屏蔽:普通的自动化库(如 pyautogui)发送的是应用层指令,无法被基于 DirectX 的全屏游戏识别。 本项目通过 Flutter 打造极致的笔记本

By Ne0inhk