邀请竞争似乎很奇怪,但微软(Microsoft)现在允许你在Windows中运行(Windows)Linux。它比您想象的更容易安装,比我们想象的更灵活和强大。
为什么要为Linux安装(Install)Windows子系统(Subsystem)?
将一个操作系统 (OS) 安装在另一个操作系统中似乎是矛盾的。重点是什么?为什么是Linux?我们可以想到六个在Windows中使用(Windows)Linux的理由。
1. Linux的 Windows(Linux)子系统(Subsystem)免费且简单
最明显的答案是Linux是免费的。但是如果很难使用,免费的东西有什么用呢?好消息是适用于Linux的(Linux)Windows 子系统(Windows Subsystem)( WSL ) 安装或卸载简单、简单且快速,因此如果您只是对Linux感兴趣,值得一试。
2. 适用于 Linux 的 Windows子系统(Subsystem)不需要虚拟(Require)机
如果您不想安装Hyper-V、VirtualBox或VMWare等虚拟机 (VM) 主机,WSL是您的最佳选择。它占用的空间和资源也更少,例如CPU和RAM。
3.适用于Linux 的Windows 子系统(Windows Subsystem)可以使用许多 Linux 发行版(Linux Can Use Many Linux Distributions)
在撰写本文时,Microsoft Store中有 17 个(Microsoft Store)Linux发行版(或“发行版”)可用。其中包括Ubuntu Desktop and Server、Debian、Kali、SUSE Linux Enterprise Server、OpenSUSE和Oracle Linux的不同版本和变体。
您还可以使用以下PowerShell命令查看所有可用的发行版:
wsl –list –在线(wsl –list –online)
4.用于职业发展(Career Development)的Linux的 Windows(Linux)子系统(Subsystem)
您可以了解 Linux 和各种 Linux 发行版(various Linux distros),如Ubuntu、Debian GNU/Linux、Kali和Alpine WSL,供工作或学校使用。Linux在服务器市场占有相当大的份额,越来越多的组织正在将Linux用于桌面。
学生可以将其用于教程,而不是去计算机实验室。安全(Security)研究人员可以使用Kali 和其他 Linux 黑客发行版(Kali and other Linux hacking distros)及其许多包含的工具。许多 Web 开发人员、程序员和人工智能研究人员可能会使用 Debian 或 Alpine WSL作为他们的开发环境,因为他们有内置的开发人员工具。
5. 适用于开源应用程序(Open Source Apps)的Linux的 Windows(Linux)子系统(Subsystem)
大多数开源软件 ( OSS ) 首先是针对Linux环境开发的。因此,OSS正在成为多个行业的标准,例如游戏开发、图形设计和物联网(Things)( IoT(Internet) )嵌入式(IoT)系统。
考虑所有开源软件,这些软件通常是免费的。希望你有Photoshop吗?考虑使用 GIMP(using GIMP)。想学CAD但买不起AutoCAD?试试 OpenSCAD(Try OpenSCAD)。想要将您的视频编辑提升到一个新的水平,但Adobe Premiere却遥不可及?Linux有 Openshot。
更令人印象深刻的是,您可以在它们的窗口中运行这些Linux GUI应用程序,就像它们是Windows应用程序一样。在Hyper-V(Hyper-V)、VirtualBox或第二台物理计算机中不需要单独的虚拟机。您可以在Windows中使用 Visual Studio并在Linux上的(Linux)GIMP中进行照片编辑,而不会影响您的工作流程。
6. Windows 终端(Windows Terminal Runs Multiple Distros)同时运行多个发行版(Once)
如果您是Windows Terminal及其多标签功能的粉丝,您会喜欢同时运行多个Linux发行版,每个发行版都在自己的标签中。
我应该使用 WSL 1 还是 WSL 2?
WSL有两个版本:WSL 1和WSL 2。WSL默认为版本 2。这对大多数人来说都很好。但是,如果您不确定您的系统是否可以处理完整的Linux 内核(Linux kernel)安装,或者您不会使用Docker 之(Docker)类的东西,那么WSL 1就可以了。
如果您改变主意,该版本很容易更新。作为管理员,打开 PowerShell(open PowerShell)或命令(Command)行并使用以下 wsl.exe 命令:
wsl –set-default-version 2或wsl –set-default-version 1
(Install Windows Subsystem)使用PowerShell安装适用于Linux的(Linux)Windows 子系统
您可以使用PowerShell或命令行界面 ( CLI ) 安装 WSL。如果你还没有学过PowerShell,那也没关系。wsl.exe 命令可以在其中任何一个中使用。
- (Open PowerShell)以管理员身份打开 PowerShell并运行 cmdlet wsl –install。这会默认安装具有完整Linux内核和Ubuntu发行版的WSL 2版本。(WSL 2)
如果显示 wsl.exe 帮助文本,则表明WSL已安装。
安装需要几分钟,然后提示您重新启动Windows。
- 当Windows重新启动并且您登录时,会打开一个 bash shell 窗口,然后继续安装Ubuntu。它会要求您输入新的UNIX用户名和新密码(New Password)。输入这些后,安装完成。
注意:这将为Ubuntu(Ubuntu)安装 bash shell 。它不是图形用户界面 ( GUI )。要启用它,还有其他步骤和先决条件。但是,您现在可以在Windows计算机
上使用Linux bash shell 命令。
(Install Windows Subsystem)使用控制面板(Control Panel)安装适用于Linux的(Linux)Windows 子系统
- 打开开始(Start)菜单并选择控制面板(Control Panel)。
- 选择程序和功能。
- (Select Turn Windows)选择打开或关闭Windows功能。这需要管理员权限。
- 向下滚动(Scroll)并选择适用于Linux的(Linux)Windows 子系统(Windows Subsystem),然后选择确定。
安装开始。完成后,Windows需要重新启动您的 PC 消息显示。选择(Select Restart)立即重新启动。
重新启动后,在Windows上从开始(Start)菜单打开Ubuntu ,或者在(Ubuntu)PowerShell或命令提示符(Command Prompt)中,使用 wsl.exe 命令。
如何卸载适用于Linux的(Linux)Windows 子系统(Uninstall Windows Subsystem)?
要删除WSL,您必须先卸载任何Linux操作系统。然后,您可以删除Windows中的支持组件。通过Windows设置最容易做到这一点。
- 打开Windows 设置(Windows Settings),转到应用程序(Apps),然后选择应用程序(Apps)和功能。
- 搜索您安装的Linux发行版。(Linux)选择垂直三点菜单并选择卸载(Uninstall)。
- 搜索“windows 子系统”,选择三点菜单,然后选择卸载(Uninstall)。对适用于Linux WSLg 预览版的(Linux WSLg Preview)Windows 子系统(Windows Subsystem)和(Windows Subsystem)适用于Linux 更新(Linux Update)的 Windows 子系统(如果有的话)执行此操作。
- 重新启动 Windows(Restart Windows),并且应该卸载
WSL 。
如何从Windows访问(Windows)Linux 文件系统(Linux File System)?
与在虚拟机中使用Linux不同,从(Linux)Linux访问(Linux)Windows文件很容易,反之亦然。
打开文件资源管理器(Open File Explorer)并在左侧导航窗格中选择Linux 。在Windows和Linux之间移动文件时,请确保使用副本,而不是原始文件。存在一些文件类型兼容性问题,有时文件会损坏。
如何修复错误消息“\wsl.localhost 不可访问”
第一次通过文件资源管理器打开(File Explorer)Linux文件系统时,您可能会遇到此错误。
Windows将此连接视为Windows和Linux计算机之间的物理连接。所以你必须告诉它网络存在并且可以访问。您将通过Windows 注册表(Windows Registry)执行此操作。如果您在Registry中工作不自在,请询问适合的人。注册表(Registry)中的错误可能导致Windows停止工作。也总是备份 Registry(make a backup of the Registry)。
- 打开注册表编辑器(Registry Editor)。在左窗格中,导航到以下位置:
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlNetworkProvider/HwOrder
- 在右侧,双击PROVIDERORDER键。
- 将 P9NP(Add P9NP)(后跟一个逗号且没有空格)添加到列表的前面,然后选择确定。
- 回到NetworkProvider容器中,打开Order键。双击右侧
的PROVIDERORDER 。
- 将 P9NP 添加(Add P9NP)到列表的前面(一个逗号,没有空格),选择 OK,然后关闭Registry Editor。
您现在可以通过Windows 文件资源管理器(Windows File Explorer)打开Ubuntu文件系统。如果错误仍然存在,请重新启动Windows,它应该可以工作。
如何从Linux访问(Linux)Windows 文件系统(Windows File System)?
- 在Linux bash shell 中,使用命令cd ../..移动到根目录。然后使用ls命令列出目录和文件。您会看到它们都是Windows目录和文件。
- 要查找您的文件,请使用以下命令进入您的文档文件夹,其中 username 是您在 Windows 中的用户目录的名称:
cd users/username/documents
如果您需要访问其他内容,只需使用cd和ls直到找到它。由于存在损坏文件的风险,请确保您只复制文件,而不是移动它们。
我还能(Else)用适用于Linux的(Linux)Windows 子系统(Windows Subsystem)做什么?
启用 WSL 后,您的Windows计算机上就有了一个完整的Linux环境。或者可能是几个Linux环境。在Linux(Linux)中您能想到的任何事情,现在都可以做。查看我们与Linux相关的文章和教程以获得一些想法。
How to Install Windows Subsystem for Linux in Windows 11
It seems odd to invіte the competition in, but Microsoft now lets you run Linux inside Windows. It’s easier to install than you think and more flexible and powerful than we іmagined.
Why Install Windows Subsystem for Linux?
It seems contradictory to install one operating system (OS) inside another. What’s the point? And why Linux? We can think of six reasons to use Linux in Windows off the top of our heads.
1. Windows Subsystem for Linux is Free and Easy
The most obvious answer is that Linux is free. But what good is something free if it’s hard to use? The good news is that Windows Subsystem for Linux (WSL) is easy, simple, and fast to install or uninstall, so it’s worth trying if you’re just curious about Linux.
2. Windows Subsystem for Linux Doesn’t Require a Virtual Machine
If you don’t want to install a virtual machine (VM) host like Hyper-V, VirtualBox, or VMWare, WSL is the way to go. It takes up less space and resources like CPU and RAM too.
3. Windows Subsystem for Linux Can Use Many Linux Distributions
At the time of writing, 17 Linux distributions (or “distros”) were available in the Microsoft Store. These include different versions and variations of Ubuntu Desktop and Server, Debian, Kali, SUSE Linux Enterprise Server, OpenSUSE, and Oracle Linux.
You also can use the following PowerShell command to see all available distros:
wsl –list –online
4. Windows Subsystem for Linux for Career Development
You could learn about Linux and various Linux distros like Ubuntu, Debian GNU/Linux, Kali, and Alpine WSL for work or school. Linux has a significant market share of servers, and more organizations are using Linux for the desktop.
Students can use it for tutorials instead of going to the computer lab. Security researchers can use Kali and other Linux hacking distros and its many included tools. Many web developers, programmers, and artificial intelligence researchers may use Debian or Alpine WSL as their development environment as they have built-in developer tools.
5. Windows Subsystem for Linux for Open Source Apps
Most open-source software (OSS) is developed first for a Linux environment. As a result, OSS is becoming the standard in several industries, like game development, graphic design, and Internet of Things (IoT) embedded systems.
Consider all the open source software, which is often free. Wish you had Photoshop? Consider using GIMP. Want to learn CAD but can’t afford AutoCAD? Try OpenSCAD. Want to take your video editing to the next level, but Adobe Premiere is out of reach? Linux has Openshot.
Even more impressive is that you can run these Linux GUI apps in their windows as if they were Windows apps. There’s no need for a separate virtual machine in Hyper-V, VirtualBox, or a second physical computer. You could use Visual Studio in Windows and do photo edits in GIMP on Linux without disturbing your workflow.
6. Windows Terminal Runs Multiple Distros at Once
If you’re a fan of Windows Terminal and its multi-tab feature, you’ll love that you can run several Linux distros simultaneously, each in its own tab.
Should I use WSL 1 or WSL 2?
There are two versions of WSL: WSL 1 and WSL 2. WSL defaults to version 2. That’s fine for most people. However, if you’re not sure your system can handle a full Linux kernel install, or you will not use things like Docker, then WSL 1 is fine.
The version is easy to update if you change your mind. As an administrator, open PowerShell or the Command line and use the following wsl.exe command:
wsl –set-default-version 2 or wsl –set-default-version 1
Install Windows Subsystem for Linux with PowerShell
You can install WSL with either PowerShell or the command line interface (CLI). If you haven’t learned PowerShell, that’s okay. The wsl.exe commands work in either.
- Open PowerShell as an administrator and run the cmdlet wsl –install. This installs the WSL 2 version with a full Linux kernel and the Ubuntu distro by default.
If the wsl.exe help text shows, WSL is already installed.
It takes a few minutes to install and then prompts you to reboot Windows.
- When Windows reboots and you sign in, a bash shell window opens, and the Ubuntu installation continues. It will ask you to Enter new UNIX username and New Password. After you enter these, the installation is complete.
Note: This installs the bash shell for Ubuntu. It’s not the graphical user interface (GUI). There are additional steps and prerequisites to enable that. However, you can now use Linux bash shell commands on your Windows computer.
Install Windows Subsystem for Linux with Control Panel
- Open the Start menu and select Control Panel.
- Select Programs and Features.
- Select Turn Windows features on or off. This requires administrator privilege.
- Scroll down and select Windows Subsystem for Linux and then select OK.
The installation begins. When it’s done, the Windows needs to reboot your PC message shows. Select Restart now.
After the restart, open Ubuntu on Windows from the Start menu, or in PowerShell or Command Prompt, use the wsl.exe command.
How Do I Uninstall Windows Subsystem for Linux?
To remove WSL, you must uninstall any Linux operating systems first. You can then remove the supporting components in Windows. It’s easiest to do this through Windows settings.
- Open Windows Settings, go to Apps, then select Apps & features.
- Search for the Linux distros you installed. Select the vertical three-dot menu and select Uninstall.
- Search for “windows subsystem,” select the three-dot menu, and then select Uninstall. Do this for Windows Subsystem for Linux WSLg Preview and Windows Subsystem for Linux Update if those are there.
- Restart Windows, and WSL should be uninstalled.
How Do I Access the Linux File System from Windows?
Unlike using Linux in a virtual machine, it’s easy to access Windows files from Linux and vice versa.
Open File Explorer and select Linux in the navigation pane on the left. When moving files between Windows and Linux, make sure you use a copy, not the original. There are some filetype compatibility issues, and sometimes the file gets corrupted.
How to Fix the Error Message “\\wsl.localhost is not accessible”
You may get this error the first time you open the Linux filesystem through File Explorer.
Windows treats this connection like a physical connection between Windows and Linux computers. So you must tell it the network exists and is accessible. You’ll do this through the Windows Registry. If you’re not comfortable working in the Registry, ask someone who is. A mistake in the Registry can cause Windows to stop working. Always make a backup of the Registry, too.
- Open the Registry Editor. In the left pane, navigate to the following location:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider/HwOrder
- On the right, double-click the PROVIDERORDER key.
- Add P9NP (followed by a single comma and no spaces) to the front of the list and then select OK.
- Back in the NetworkProvider container, open the Order key. Double-click PROVIDERORDER on the right.
- Add P9NP to the front of the list (one comma, no spaces), select OK, and then close Registry Editor.
You can open the Ubuntu filesystem through Windows File Explorer now. If the error persists, restart Windows, and it should work.
How Do I Access the Windows File System from Linux?
- In the Linux bash shell, use the command cd ../.. to move to the root. Then use the ls command to list the directories and files. You’ll see that they’re all Windows directories and files.
- To find your files, use the following command to get to your documents folder, where username is the name of your user directory in Windows:
cd users/username/documents
If you need to access something else, just use cd and ls until you find it. Ensure you only copy files, not move them, due to the risk of corrupting the file.
What Else Can I Do With Windows Subsystem for Linux?
When you enable WSL, you’ve got an entire Linux environment on your Windows computer. Or maybe several Linux environments. Whatever you can think of doing in Linux, you can now do. Take a look at our Linux-related articles and tutorials to get some ideas.