[ How-to Guide ] ___ WSL : 安装、配置与升级

本文详细介绍了如何在Windows10上安装、配置和升级WindowsSubsystemforLinux(WSL),包括WSL1和WSL2的区别,以及如何处理文件系统、性能调优和常见问题。适合开发者了解和使用这一跨平台工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、主题


本文旨在详细介绍如何在 Windows 系统中安装、配置以及升级 Windows Subsystem for Linux (WSL)。通过本文所述步骤,您将能够顺利启用 WSL 功能,并根据需求在 WSL 1 与 WSL 2 之间进行选择与升级。为确保安全,请在操作前备份数据或创建系统还原点。

二、前言


WSL 是微软推出的一项功能,允许用户在 Windows 系统中直接运行 Linux 环境,从而获得 Linux 命令行工具和开发环境。无论是对跨平台开发、系统测试还是日常使用,WSL 都能提供灵活、高效的解决方案。本文将分别说明安装与配置 WSL 的基本步骤,以及如何升级到性能更优的 WSL 2 版本,帮助您更好地利用这一功能。

三、概述


WSL(Windows Subsystem for Linux)是微软在 Windows 10 及更高版本中推出的一项关键功能,使用户无需双启动或虚拟机即可直接运行 Linux 环境。该功能为开发者提供了在 Windows 上使用 Linux 命令行工具、安装软件包以及访问 Linux 文件系统的便捷途径,极大地提升了跨平台开发与测试的效率。

(一)核心功能


WSL 能够让用户在 Windows 环境中体验到 Linux 系统的灵活性和强大功能。通过 WSL,您可以:

  • 直接运行 Bash 命令行和 Linux 应用程序;

  • 无缝访问 Windows 文件系统,方便数据交互;

  • 利用 Linux 开发工具和生态系统,提高开发效率。

(二)版本


WSL 目前有两个主要版本,各具特色:

  • WSL 1:基于系统调用翻译技术,启动快、资源占用低,但在文件系统和网络性能方面存在一定限制。
  • WSL 2:基于 Hyper-V 虚拟化技术,采用真实的 Linux 内核,提供更好的性能、系统调用兼容性,并支持 Docker 等功能。

WSL 1 直接在 Windows 内核中运行,通过系统调用翻译实现 Linux 兼容性,适合对跨系统文件访问速度要求较高的场景。WSL 2 则使用轻量级虚拟机运行完整的 Linux 内核,提升了系统调用兼容性和文件 I/O 性能,但跨 OS 文件访问速度略逊于 WSL 1。

功能WSL 1WSL 2
Windows-Linux 无缝集成
启动速度快
低资源占用
兼容 VMware/VirtualBox
托管 VM
完整 Linux 内核
完全系统调用兼容性
跨 OS 文件访问性能
systemd 支持
IPv6 支持

选择指南

  • 选择 WSL 1

    • 需要高效访问 Windows 文件(如跨系统编译)。
    • 依赖 VMware 或 VirtualBox 旧版本。
    • 需要更低的资源占用。
  • 选择 WSL 2

    • 需要更好的 Linux 兼容性(如 systemd)。
    • 运行 Docker 或依赖完整 Linux 内核的应用。
    • 需要更高的文件 I/O 性能(存储在 Linux 子系统内的文件)。

用户可根据需求选择合适版本,同时可随时在 WSL 1 和 WSL 2 之间切换。

四、安装与配置

(一)准备工作


确保您的 Windows 10 更新至最新版本,以获得最佳的兼容性和安全性。您可以通过 “设置” > “更新和安全” > “Windows更新” 来检查并安装最新更新。

(二)安装 WSL


1. 启用 Windows 子系统功能

打开 PowerShell(以管理员身份运行),输入以下命令启用 “适用于 Linux 的 Windows 子系统”:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

完成后请重启计算机。

2. 安装 Linux 发行版

重启后,打开 Microsoft Store,搜索并选择您喜欢的 Linux 发行版(如 Ubuntu、Debian 或 Fedora 等),点击安装。

(三)配置 Linux 发行版


1. 初始化设置

在开始菜单中找到并启动你安装的 Linux 发行版。首次启动时,它会花费一些时间来解压和安装,完成后会提示你创建一个新的用户账户(用户名和密码)。

2. 更新系统

为确保所有软件包均为最新状态,建议在 Linux 环境中执行以下命令:

  • 对于基于 Debian 的发行版:如Ubuntu、Debian
sudo apt update && sudo apt upgrade
  • 对于基于 Fedora 的发行版:
sudo dnf update

3. 探索 Linux

现在你可以开始探索 Linux 的世界了。尝试运行一些基本的命令,安装软件包,或者探索特定于你的发行版的功能。

通过上述步骤,你可以在没有预先安装 WSL 的电脑上安装并开始使用 WSL 1。WSL 默认安装的是 WSL 1,它为运行 Linux 二进制文件提供了一个兼容层。WSL 1 通常对性能和内存使用有较好的表现,但它不支持某些 Linux 特定功能,如完整的系统调用兼容性。如果未来你决定需要 WSL 2 的特定功能(如改进的文件系统性能,或者完整的 Linux 内核),你可以随时按照提供的步骤将你的 WSL 实例升级到 WSL 2。

五、升级


(一)升级前准备


WSL 提供两种版本:WSL 1 与 WSL 2。WSL 2 依托于 Hyper-V 虚拟化技术和真实 Linux 内核,在系统调用兼容性和文件系统性能方面具有明显优势,但对 Windows 版本有更高要求。请先确认您的 Windows 至少为版本 1903,并使用命令检查操作系统版本。

winver

(二)升级步骤


1. 更新 WSL 的内核

使用终端或命令提示符运行以下命令以确保具有最新版本,更新 WSL 内核的步骤可能会因 Windows 版本的不同而有所差异

wsl --update

此命令会从 Microsoft/WSL GitHub Releases 下载最新内核,若卡住或无响应,则直接跳转手动访问 WSL 官方 GitHub Releases 下载最新版 msi 安装包并运行。

2. 启用虚拟机平台功能

同样在管理员模式下运行 PowerShell,启用虚拟机平台功能:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

重启计算机后继续操作。

3. 下载 Linux 内核更新包

请访问 微软官方 WSL 2 安装指南页面,下载并安装最新的 Linux 内核更新包。

4. 将 WSL 默认版本设置为 2

在 PowerShell 中执行以下命令,将 WSL 默认版本调整为 2:

wsl --set-default-version 2

5. 升级已安装的 Linux 发行版

如果您已有 WSL 1 的 Linux 发行版,可通过以下命令升级至 WSL 2(将 替换为您的发行版名称,如 Ubuntu):

wsl --set-version <DistributionName> 2

<DistributionName> 替换为你的 Linux 发行版的名称,例如Ubuntu

6. 验证升级结果

运行命令:

wsl -l -v

该命令将列出所有已安装的 Linux 发行版及其对应的 WSL 版本,确认升级是否成功。这将列出所有已安装的 Linux 发行版及其对应的 WSL 版本。

六、交互


WSL 提供了多种与 Windows 系统交互的方式,提高了工作效率和便捷性。

  1. 文件系统访问:从 WSL 中,你可以通过 /mnt/c/(或其他盘符)来访问 Windows 文件系统。这意味着你可以直接从 WSL 访问 Windows 中的文件和目录,如果在 /mnt 目录下没有对应的盘符,则需要通过创建目录来让文件系统对应。

  2. 运行 Windows 程序:你可以从 WSL 终端运行 Windows 程序。只需在 WSL 命令行中输入程序的名字(例如,notepad.exe),就可以启动 Windows 的记事本程序。

  3. 剪贴板共享:你可以在 WSL 和 Windows 之间共享剪贴板内容。使用 clip.exe 来访问 Windows 的剪贴板。

  4. 开发环境集成:对于开发人员来说,可以利用 Visual Studio Code的Remote - WSL 扩展,直接在 WSL 环境中开发,享受无缝的代码编辑和调试体验。

七、问题


  1. 文件权限:在 WSL 中编辑 Windows 文件系统上的文件时,请注意文件权限问题,以避免意外修改或数据丢失。

  2. 性能调优:对于 WSL 2,由于其使用虚拟化技术,可能需要对内存使用进行调整。你可以通过修改 .wslconfig 文件来限制 WSL 2 使用的资源。

  3. 网络问题:WSL 2 使用虚拟网络适配器,可能会与某些 VPN 软件冲突。如果遇到网络连接问题,尝试调整 VPN 设置或临时禁用 VPN。

八、总结


通过上述步骤,您已成功在 Windows 上安装、配置并升级 WSL。WSL 为开发者提供了跨平台开发的高效环境,既兼具 Linux 的灵活性,也保留了 Windows 的便捷性。在实际应用中,您可根据项目需求选择合适的 WSL 版本,并在遇到问题时参考本文提供的调优与解决方案。建议在操作前创建系统还原点,以防不测;同时,定期检查 Windows 更新和 WSL 内核更新,以确保系统安全和最佳性能。

九、参考


WSL 文档

### IsaacLab Installation Guide for Ubuntu 20.04 For installing IsaacLab on an Ubuntu 20.04 system, a series of preparatory steps must be completed to ensure compatibility and functionality. #### Preparing the System Environment Ensure that all necessary software is installed as described in tutorials covering essential installations for Ubuntu 20.04[^2]. This includes setting up the correct time zone, configuring input methods such as Sogou Pinyin, deploying Anaconda for Python development environments, using Terminator terminal emulator, ensuring Nvidia drivers are properly set up which is crucial since IsaacLab relies heavily on GPU acceleration capabilities provided by Nvidia hardware. #### Installing CUDA Toolkit Since IsaacLab requires CUDA support, follow guidelines similar to those outlined for WSL 2 but adapted specifically for native Linux distributions like Ubuntu 20.04[^4]. Install the appropriate version of the CUDA toolkit compatible with your graphics card model through either package managers or direct downloads from Nvidia's official website. ```bash sudo apt-get update && sudo apt-get install cuda ``` After installation completes successfully, verify it works correctly: ```bash nvcc --version ``` #### Setting Up cuDNN Following successful setup of CUDA, proceed to configure cuDNN according to instructions found within documentation related to Autoware environment configuration under Ubuntu 20.04[^3]: Download `libcudnn8` and its developer library corresponding to the chosen CUDA version before executing commands below: ```bash sudo dpkg -i libcudnn8_*.deb sudo dpkg -i libcudnn8-dev_*.deb ``` Confirm proper integration via running tests included inside sample directories bundled alongside cuDNN packages. #### Obtaining and Configuring IsaacLab Once prerequisites have been met, obtain access rights to download IsaacSim/IsaacLab SDK directly from Nvidia’s developer portal after registering there first if not done already. Follow detailed guides available online regarding unpacking archives, placing files into designated locations while adhering closely to any specific requirements mentioned during this process concerning dependencies management tools used throughout projects built around Omniverse platform components including IsaacLab itself. Finally, customize settings based upon personal preferences or project needs following post-installation procedures recommended officially by developers behind these applications. --related questions-- 1. What versions of CUDA should one choose when preparing their machine learning workstation? 2. How does adjusting system locale affect non-English speaking users' experiences on fresh installs of Ubuntu-based systems? 3. Can you explain how to troubleshoot common issues encountered after updating Nvidia drivers on Linux machines? 4. In what ways can integrating Jupyter notebooks enhance productivity within data science workflows conducted over Conda-managed virtual environments? 5. Are there alternative text editors besides Vim/GNU Emacs suitable for beginners who wish to write scripts efficiently without steep learning curves?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值