惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
量子位
M
Microsoft Research Blog - Microsoft Research
Microsoft Azure Blog
Microsoft Azure Blog
Jina AI
Jina AI
罗磊的独立博客
V
Visual Studio Blog
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog

DEV Community

LocalFind Gemma — AI-Powered Semantic Search and Chat for Your Local Files AI-dy: On-Device Emergency First Aid with Gemma 4 Datrix: Chat With Your Data Using Gemma 4 — Charts, ML Models, No Code Understanding Reinforcement Learning with Human Feedback Part 4: Teaching Models Human Preferences The Architect’s Pivot: Mastering Parallel Agent Orchestration with Antigravity 2.0 Quidditch - Powered By PostgreSQL and ASP.NET Build a Database Connection Framework In 133 Lines Of Code How I mapped 600+ GPS audio-guides as a solo dev (and why I finally did it after 8 years) A Floating Productivity Panel I Built for Android The Microsecond Lie: Why your Go timers are lying about the GPU Google used 6,000 open-source contributors then locked the door. Classic. Terceira semana tentando voltar ao mercado de trabalho How I turned a Python function into a web app in one decorator I Got Tired of Heavy Design Tools… So I Built My Own 😩 The Google I/O 2026 Moment That Quietly Changed How I See AI Getting Started: Run Your First Local LLM in 5 Minutes Building a 1% Fee Web3 Marketplace for Study Notes: Is a 5% Shift Sustainable? Full Agentic Stack - 5 Ideias da Arquitetura 'AI-First' que Vão Mudar a Forma Como Você Desenvolve Software Build Club Week Four: the part of Themis Lex I never explained I Tried Google Antigravity 2.0 Here's What It Actually Feels Like to Code With AI Agents By Isaac Yakubu | Google I/O 2026 Challenge Submission The growth quest picks what you avoid, not what you're already good at Firebase AI Logic's Template-Only Mode Is the Security Feature We Actually Needed Hardware Guide: What Do You Actually Need to Run Local LLMs? Constitutional Exception Committees: A Pattern for AI Agent Constraint Governance Veltrix's Treasure Hunt Engine: Optimized for Long-Term Survival, Not Just Scalability Open WebUI: Your Local ChatGPT Build a streaming UI without overcomplicating it The Cost of Kernel CVE Patching Frequency in SLA Commitments Gemma 4 Runs on a Raspberry Pi. Let That Sink In. The Git Filesystem - Recreating the Content-Addressable Database Why I Still Believe Our Event-Driven Architecture Was The Right Call For Veltrix Local RAG: Chat With Your Documents (Open Source, Private) GGUF & Modelfile: The Power User's Guide to Local LLMs What Excited Me Most at Google I/O 2026 OSS assemble! Kilo Code is launching on Product Hunt. Join the launch! https://www.producthunt.com/products/kilocode Your Organizational AI Adoption Metrics Are Lying (Plus How to Measure Real Adoption) Building a Production-Grade MLOps Home Lab on Windows — K8s, LLM, RAG & GitLab CI The Moment I Realized AI Agents are Changing Software Forever Prisma Generator NestJS DTO — pluggable DTOs with annotations and custom generators I Spent a Month Testing Decentralized Poker Sites. Here's What Actually Works. DeepSeek-R1: The $0 o1 Alternative You Can Run Right Now The PHP Stack I Built TrustGate On — And Why I'd Do It Differently Today Building High-Throughput Data Pipelines: Why Chaining Encryption and Compression is a Performance Killer Optic is dead. A 2026 migration guide for OpenAPI breaking changes Smart Blind Stick, Mini Project The NSA just published an MCP security playbook. We created Agent Trust Transport Protocol ATTP - Implement today with MCPS Symfony 8 AWS Secrets Bundle Canlı TV Platformu Geliştirirken Öğrendiğim Teknik Dersler: Streaming, Flussonic ve Performans Gemma 4 Is Powerful — But Production AI Still Needs Governance What RepoSignal Surfaced in React — and Why Review Alone Doesn't Catch Everything
安装终端和WSL(Windows子系统 for Linux)
Phillip A. W · 2026-05-24 · via DEV Community

如果你是 Windows 平台的网页开发者,Windows 子系统 for Linux (WSL) 是必不可少的。本教程将带你了解 WSL 是什么,为什么你应该使用它,以及如何安装和配置它用于开发.

注意:本指南仅适用于 Windows.如果你使用的是 macOS,你已经拥有基于 Unix 的终端,所以你可以跳过本教程,继续学习系列中的下一个教程。

我真的需要WSL吗?

简答:是的,如果你在Windows上进行Web开发。

大多数Web开发工具、软件包和教程都假设基于Unix的环境(Linux或macOS)。虽然你可以 在 Windows 上使用 PowerShell 或 cmd.exe 开发,你将不断遇到与包管理器、构建工具和假设使用 Unix shell 的开源项目之间的兼容性问题。WSL 允许你在 Windows 上直接运行 Linux,而无需虚拟机的额外开销.

WSL 到底是什么?

Windows子系统 for Linux (WSL)是一个兼容层,它允许您直接在Windows上运行一个真正的Linux环境。它在一个轻量级的虚拟机中运行真实的Linux内核,同时与Windows紧密集成——您既获得了Linux的速度和兼容性,也享受了Windows的便利.

WSL is a layer between Windows & Linux (Generated with ChatGPT)

什么是Linux发行版(distro)?

Linux 发行版是 Linux 内核的打包版本,捆绑了特定的工具、包管理器和系统实用程序。常见的发行版包括 Ubuntu、Debian、Fedora 和 Alpine。对于开发,Ubuntu 是最适合初学者且支持最广泛的选项.

为什么选择 WSL 而不是 Linux 双启动?

双启动让你能在启动时选择操作系统,但如果你不重启,就无法同时使用 Windows 和 Linux。WSL 让你能在同一时间运行这两个环境,并且它们之间可以无缝访问文件。你得到了两者的最佳结合。

为什么选择 WSL 而不是虚拟机 (VM)?

虚拟机比WSL使用更多的系统资源(CPU、内存、存储)。WSL轻量级,启动更快,与Windows的集成更好。如果你资源受限或想要一个快速的开发环境,WSL更优越。

使用WSL会损失什么吗?

WSL 为你提供了一个 Linux shell 和命令行工具,但它默认不会运行完整的图形 Linux 桌面。你仍然需要使用 Windows 来运行你的 GUI 应用程序(VS Code、浏览器等),并通过终端访问 Linux。这正是大多数开发人员想要的。


💻 安装 Windows Terminal (推荐)

Windows Terminal 是微软的现代终端应用程序。它不使用默认的 Windows PowerShell 或 cmd.exe,而是提供更干净、更可定制的体验,具有多个标签页、主题和无缝的 WSL 集成.

什么是终端?FAQ: 操作系统、终端& Shell 中所述,终端是运行 shell(命令行解释器)的应用程序。Windows Terminal 是容器应用程序,而 Bash/Zsh/PowerShell 是它里面的 shell。查看那个 FAQ 以获得更深入的解释.

从 Microsoft Store 安装:

  1. 打开 Microsoft Store(在 Windows 开始菜单中搜索“Microsoft Store”)
  2. 搜索“Windows Terminal”
  3. 点击“安装”

好了!安装完成后,Windows Terminal 即可使用。你将在下一节中使用它来运行 WSL 安装命令。安装 WSL 后,Windows Terminal 将自动将 Ubuntu 识别为可用的 Shell 配置文件.


💻 安装 WSL

这些说明适用于 Windows 10 (Build 19041+) 或 Windows 11

第一步:检查您的 Windows 版本

按下Win + R,输入winver,然后按 Enter。您需要:

  • Windows 10:版本 21H2 或更高版本(构建版本 19041 或更高)
  • Windows 11:任何版本

如果您需要更新,请前往设置 → 系统 → 关于 → Windows 更新。

第 2 步:启用 WSL

以管理员身份打开 Windows Terminal

  1. 右键点击 Windows Terminal 图标(在开始菜单或任务栏中)
  2. 选择 "以管理员身份运行"
  3. 你可能会看到一个提示询问 "是否允许此应用进行更改?" — 点击 "是"

一旦 Windows Terminal 以管理员权限打开,您将看到一个命令提示符。无论它显示哪种 shell(PowerShell、cmd.exe 或其他),wsl --install 命令都可以在任何一种 shell 中使用。只需粘贴或输入:

wsl --install

进入全屏模式 退出全屏模式

这个单一命令将:

  1. 启用 WSL 和虚拟机平台功能
  2. 下载并安装Ubuntu(默认发行版)
  3. 自动为您配置最新版本

注意:如果您看到关于虚拟化的错误,您可能需要在BIOS中启用它。重启您的计算机,进入BIOS(通常在启动时按F2、F10、DEL或ESC——具体因制造商而异),并查找“虚拟化”或“Intel VT-x”/“AMD-V”并启用它。

第 3 步:重启您的计算机

WSL 需要系统重启。立即执行此操作.

第 4 步:完成 Ubuntu 设置

重启后,Ubuntu 可能会自动启动,或者您可能需要手动启动:

如果 Ubuntu 自动启动: 您将看到一个终端窗口提示您创建用户名和密码。跳到下一节。

如果 Ubuntu 没有自动启动: 打开 Windows Terminal,点击工具栏中的下拉箭头,并选择 "Ubuntu" 以启动设置。

无论哪种方式,你都会看到一个设置提示:

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows user name.
For more information visit: https://aka.ms/wsluserstore
Enter new UNIX username: [type your username]
New password: [type a password]
Retype new password: [confirm password]

进入全屏模式 退出全屏模式

选择一个简单的用户名(例如,dev 或你的名字)。 记住这个密码 — 你需要在 WSL 中进行管理任务时使用它.

https://pawper.dev/?v=entry&cat=logs&entry=latest&modal=log&id=guide-password-management-cybersecurity-beginners

第 5 步:验证安装

在当前打开的 Ubuntu 终端中,验证一切是否正常:

wsl --version

全屏模式 退出全屏模式

你应该看到显示 WSL 版本 2.x 的输出。

同时验证你的 Linux 发行版:

lsb_release -a

全屏模式 退出全屏模式

你应该看到 Ubuntu 的信息。

来源 / 附加材料:

https://docs.microsoft.com/en-us/windows/wsl/install

https://docs.microsoft.com/en-us/windows/wsl/about

https://docs.microsoft.com/en-us/windows/wsl/setup/environment

第 6 步:为 Ubuntu 配置 Windows Terminal

现在 WSL 和 Ubuntu 都安装好了,你可以使用 Windows Terminal 来访问你的 Linux 环境。打开 Windows Terminal,你会看到顶部工具栏里有一个下拉箭头——点击它并选择 "Ubuntu" 来启动你的 WSL bash shell.

设为默认 Ubuntu(可选):如果你希望在启动 Windows Terminal 时自动打开 Ubuntu,请前往设置(Ctrl+,),在左侧边栏中找到“启动”,并将“默认配置文件”设置为“Ubuntu”。


为开发配置WSL

更新您的 Linux 软件包

WSL 随 Ubuntu 一起提供,但软件包列表可能已过时。运行:

sudo apt update
sudo apt upgrade -y

进入全屏模式 退出全屏模式

sudo命令以管理员权限运行命令。系统将提示您输入密码(您在步骤4中创建的密码)。

安装必备的构建工具

大多数网页开发依赖于C/C++编译器。安装它:

sudo apt install build-essential -y

进入全屏模式 退出全屏模式

这个安装了gccg++make以及其他编译原生软件包所需的工具。

(可选) 安装 Git

如果你的 Windows 机器上没有安装 Git,请在 WSL 中安装它:

sudo apt install git -y

进入全屏模式 退出全屏模式

注意:你可以使用 Windows 版本或 WSL 版本的 Git。我推荐你在两个地方都安装它,这样你就有了灵活性。

(可选)安装 Node.js(通过 nvm)

许多网络教程使用 Node.js。管理 Node 版本最简单的方法是使用 nvm(Node 版本管理器):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

进入全屏模式 退出全屏模式

然后重新加载你的 shell:

source ~/.bashrc

进入全屏模式 退出全屏模式

安装Node.js:

nvm install node

进入全屏模式 退出全屏模式

验证:

node --version
npm --version

进入全屏模式 退出全屏模式


访问您的文件

WSL和Windows共享文件系统,但您需要知道路径:

从WSL访问Windows文件

你的 WindowsC:驱动器已挂载在/mnt/c/在 WSL 中:

cd /mnt/c/Users/YourUsername/Documents

进入全屏模式 退出全屏模式

从 Windows,访问 WSL 文件

您的WSL主目录位于:

\\wsl$\Ubuntu\home\username\

进入全屏模式 退出全屏模式

打开文件资源管理器并在地址栏中输入此路径。您也可以从WSL终端使用explorer.exe ~打开它.

最佳实践

将您的开发项目保存在WSL的主目录 (~/projects/或类似路径),而不是Windows中。这可以避免文件权限问题并提高性能.

Shared file system (Generated with ChatGPT)


故障排除

WSL 无法启动 / "命令未找到"

确保你运行了wsl --install以管理员身份运行 PowerShell,不是 cmd.exe 或一个普通的 PowerShell 窗口。

虚拟化未启用

您需要在BIOS中启用虚拟化。重启您的计算机,进入BIOS(具体方法因制造商而异),然后查找“虚拟化”或“VT-x” / “AMD-V”。

WSL运行缓慢

这可能意味着您正在跨越Windows/WSL边界访问文件。请将您的项目保存在WSL的主目录中,而不是/mnt/c/

忘记了您的WSL密码

在 PowerShell 中,使用以下命令重置:

wsl --user root
passwd username

进入全屏模式 退出全屏模式

然后退出并重新以你的普通用户身份登录。


来源 / 附加材料:

https://docs.microsoft.com/en-us/windows/wsl/install
https://docs.microsoft.com/en-us/windows/wsl/about
https://docs.microsoft.com/en-us/windows/wsl/setup/environment
https://docs.microsoft.com/en-us/windows/wsl/troubleshoot/common-issues
https://docs.microsoft.com/en-us/windows/wsl/setup/windows-terminal

这篇文章是使用人工智能生成的,目的是提供实用信息。我已经审查过它的准确性,并进行了适当的编辑。