适用于Linux的Windows子系统的完整开发人员指南2

本教程详述了如何在Windows 10上安装和管理Linux子系统WSL2,实现与Linux的无缝集成,包括启用WSL2、下载Linux发行版、访问文件、运行Linux命令和Windows应用、安装Docker等。WSL2利用Hyper-V技术,提供更快的文件访问速度和更好的Linux兼容性,为开发者在Windows环境下提供完整的Linux开发体验。
摘要由CSDN通过智能技术生成

This tutorial demonstrates how to install, manage, and use a full Linux environment on your Windows 10 PC with WSL2. You’ll be running a Linux kernel and executing native applications while seamlessly sharing files and services with Windows code editors and browsers.

本教程演示了如何在具有WSL2的Windows 10 PC上安装,管理和使用完整的Linux环境。 您将运行Linux内核并执行本机应用程序,同时与Windows代码编辑器和浏览器无缝共享文件和服务。

为什么要使用Linux? (Why Use Linux?)

Your host almost certainly uses Linux. It’s fast, open source, and runs the majority of web software including:

您的主机几乎可以肯定使用Linux。 它是快速,开放源代码,并且运行大多数Web软件,包括:

  • servers (Apache, NGINX, LiteSpeed, etc.)

    服务器(Apache,NGINX,LiteSpeed等)
  • language runtimes (PHP, Python, Node.js, Ruby, etc.)

    语言运行时(PHP,Python,Node.js,Ruby等)
  • utility libraries (image manipulation, ZIP creation, emailers, etc.)

    实用程序库(图像处理,ZIP创建,电子邮件程序等)
  • databases (MySQL, MongoDB, Redis, etc.)

    数据库(MySQL,MongoDB,Redis等)
  • other dependencies (Elastic Search, RabbitMQ, proxies, etc.)

    其他依赖项(弹性搜索,RabbitMQ,代理等)

Some of these dependencies may be available on Windows and macOS, but installing and maintaining identical versions is difficult. They’re often slower and you may encounter subtle differences which will not become apparent until you deploy.

其中一些依赖项可能在Windows和macOS上可用,但是很难安装和维护相同的版本。 它们通常较慢,并且您可能会遇到细微的差异,直到您进行部署,这些差异才会变得明显。

Some developers install Linux on their desktop, but that may not be viable if you regularly require non-Linux software such as Microsoft or Adobe products. Alternative options:

一些开发人员在其桌面上安装Linux,但是如果您经常需要非Linux软件(例如Microsoft或Adobe产品),则可能不可行。 替代选项:

  1. Use two PCs or dual boot on a single device. Switching between systems can be cumbersome.

    在单个设备上使用两台PC或双启动。 系统之间的切换可能很麻烦。
  2. Run a Linux virtual machine (VM) using Hyper-V, VirtualBox, Parallels, WMware, or Vagrant. This requires considerable OS resources and reasonable IT knowledge. Sharing files between systems can be awkward.

    使用Hyper-V,VirtualBox,Parallels,WMware或Vagrant运行Linux虚拟机(VM)。 这需要大量的OS资源和合理的IT知识。 在系统之间共享文件可能很麻烦。
  3. Run web applications in Docker containers. It’s another topic to learn and Docker itself runs natively on Linux. Both the Windows and macOS editions use Linux below the surface.

    在Docker容器中运行Web应用程序。 这是另一个要学习的话题,Docker本身可以在Linux上本地运行。 Windows和macOS版本都在底层使用Linux。

什么是Linux的Windows子系统? (What is the Windows Subsystem for Linux?)

The Windows Subsystem for Linux (WSL) lets developers run a Linux environment directly on Windows 10. It’s an unmodified OS, but highly integrated into Windows and without the overhead of a virtual machine.

Windows Linux子系统(WSL)使开发人员可以在Windows 10上直接运行Linux环境。这是未经修改的OS,但高度集成到Windows中,并且没有虚拟机的开销。

WSL1 was groundbreaking and translated Linux system calls to Windows equivalents. This could be slow and several features weren’t available. WSL2 uses Hyper-V virtual machine technology so Linux compatibility is excellent and file access is up to 20x faster than before.

WSL1具有开创性,并将Linux系统调用转换为Windows等效项。 这可能很慢,并且某些功能不可用。 WSL2使用Hyper-V虚拟机技术,因此Linux兼容性出色,文件访问速度比以前快20倍。

Windows 10要求 (Windows 10 Requirements)

WSL2 is compatible with the Home, Pro, or Server editions of Windows but not Windows 10 S (although you can often upgrade to the Home edition for free).

WSL2与Windows的Home,Pro或Server版本兼容,但与Windows 10 S 兼容(尽管您通常可以免费升级到Home版本)。

The Windows May 2020 update is essential — that’s version 2004 or above. Choose the Settings cog from the Start menu, then select System followed by About. The Windows specifications are shown at the bottom of the panel:

Windows 2020年5月更新非常重要-版本2004或更高版本。 从开始菜单中选择设置齿轮,然后选择系统 ,然后选择关于Windows规格显示在面板底部:

Windows specifications

The update has been slowly rolling out since the end of May 2020. If you have a version below 2004, you may be able to trigger the update by clicking the Check for updates button in Settings, then Update & Security.

更新自2020年五月的结束已经慢慢铺开如果你有2004下方的版本,您可以通过点击设置 检查更新按钮,则更新和安全触发更新。

If 2004 remains stubbornly unavailable, you may be able to download and install it manually from microsoft.com/software-download/windows10

如果2004年仍然无法使用,则可以从microsoft.com/software-download/windows10手动下载并安装它

However, be aware some PCs report that version 2004 is currently unavailable in the Windows Update panel. You won’t be able to upgrade until Microsoft has released a fix for your device.

但是,请注意,有些PC报告Windows Update面板中当前不提供2004版。 在Microsoft为您的设备发布修复程序之前,您将无法升级。

电脑要求 (PC Requirements)

WSL2 (and Hyper-V) require hardware virtualization support to be enabled in your BIOS.

WSL2(和Hyper-V)要求在您的BIOS中启用硬件虚拟化支持。

WARNING: fiddling with your BIOS settings can trash your PC! Be careful when making changes. Consult your manufacturer’s help pages or search for online advice about your specific make and model.

警告: 摆弄BIOS设置可能会损坏您的PC! 进行更改时要小心。 请查阅制造商的帮助页面,或搜索有关特定品牌和型号的在线建议。

Hardware virtualization will be active on most devices, but you can check by rebooting, and opening the BIOS panels — typically by hitting the DEL, F2, or F10 key as the system starts. Look for Virtualization Technology, VTx or similar options. Ensure they are enabled, save, and reboot the device.

硬件虚拟化将在大多数设备上处于活动状态,但是您可以通过重新启动并打开BIOS面板进行检查-通常在系统启动时按DELF2F10键。 寻找虚拟化技术VTx或类似选项。 确保已启用它们,保存并重新启动设备。

Finally, ensure your C: drive has at least 1GB of spare disk space — ideally more. You may be able to free up some space in Settings, System, Storage or using the Disk clean-up tool in Windows Administrative Tools.

最后,确保您的C:驱动器至少有1GB的备用磁盘空间,最好是更多。 您可能可以释放“设置” ,“ 系统” ,“ 存储 ”中的某些空间,或者使用Windows管理工具中的“ 磁盘清理”工具释放空间。

At the time of writing, WSL2 will install Linux to your C: drive, although it’s possible to move it elsewhere after installation.

在撰写本文时,WSL2会将Linux安装到您的C:驱动器,尽管可以在安装后将其移动到其他位置

启用WSL2 (Enable WSL2)

The Virtual Machine Platform and Windows Subsystem for Linux features must be enabled in Turn Windows features on or off. The panel can be accessed by hitting Start and typing “features” or from the Programs and Features icon in the classic Control Panel.

必须在“ 打开或关闭Windows功能”中启用适用于Linux虚拟机平台Windows子系统功能。 可以通过单击开始并键入“功能”或从经典控制面板中的“ 程序和功能”图标来访问该面板。

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值