百科.dev
登录
> 返回资讯列表
news_article.exe
📰

如何在 Windows 上使用 WSL 安装 Linux Distro

How to Install a Linux Distro Using WSL on Windows

2026年9月4日1 次浏览来源:Dev.to 阅读原文

如果使用Windows但想要Linux开发环境,则并不一定需要双靴子,虚拟机,或第二台计算机. Linux(WSL)的Windows子系统允许您直接在Windows内部运行Linux发行. 在这个指南中,我们将安装WSL,选择Linux发行,创建Linux用户,并验证一切在起作用. WSL是什么来着? WSL(Windows Subsystem for Linux)是一个Windows特性,允许您与Windows一起运行Linux发行. 您可以使用 Linux 终端和工具, 如: Bash Git GCC Python Rust Node.js Vim SSH Linux 包管理器,而不将 Linux 安装为单独的操作系统. 对于开发者来说,WSL特别有用,因为您可以保留Windows作为普通桌面应用程序,同时使用Linux工具用于.

If you use Windows but want a Linux development environment, you don't necessarily need dual boot, a virtual machine, or a second computer. Windows Subsystem for Linux (WSL) lets you run a Linux distribution directly inside Windows. In this guide, we'll install WSL, choose a Linux distribution, create a Linux user, and verify that everything is working. What Is WSL? WSL (Windows Subsystem for Linux) is a Windows feature that allows you to run Linux distributions alongside Windows. You can use a Linux terminal and tools such as: Bash Git GCC Python Rust Node.js Vim SSH Linux package managers without installing Linux as a separate operating system. For developers, WSL is especially useful because you can keep Windows for your normal desktop applications while using Linux tools for development. Requirements Before starting, make sure you're running a supported version of Windows. Open PowerShell and run: You can also check your Windows version with: For the easiest installation method, use a modern Windows 10 or Windows 11 system with WSL support. 1. Open PowerShell as Administrator Press: Then select: or: You should see a terminal window with administrator privileges. 2. Install WSL The easiest method is: This command enables the required Windows components, installs the WSL components, and normally installs Ubuntu as the default Linux distribution. After installation, Windows may ask you to restart your computer. Restart: After Windows starts again, the Linux distribution setup should continue. 3. Check Available Linux Distributions You don't have to use Ubuntu. To see the distributions available through WSL, run: You may see distributions such as: The exact list can change over time. 4. Install a Specific Linux Distribution For example, to install Ubuntu: Or, if you want Debian: You can replace the distribution name with one from: For example: 5. Create Your Linux User After the distribution starts for the first time, Linux will ask you to create a username. For example: You might enter: Then create a password. When typing the password, nothing will appear on the screen. That's normal behavior in Linux terminals. Type the password and press Enter. 6. Verify the Installation Inside your Linux terminal, run: Then: You should see information about your Linux distribution. You can also check the current user: And check your home directory: You should get something similar to: Your Linux environment is now running. 7. Check WSL From Windows Close the Linux terminal and open PowerShell. Run: You should see something similar to: The important part is: That means you're using WSL 2. WSL 2 uses a lightweight virtualized Linux environment and provides much better Linux compatibility than the original WSL 1 architecture. 8. Start Your Linux Distribution You can start your default distribution by simply running: Or you can specify a distribution: For Debian: You can also see installed distributions with: 9. Update Linux After installing Linux, update its package information. For Ubuntu or Debian: Then upgrade installed packages: You can combine them: It's a good idea to do this before installing development tools. 10. Access Windows Files From Linux One of the useful features of WSL is that you can access your Windows drives. Your Windows drive is normally available at: For example: You can see your Windows files: Your Windows user directory might be accessible through: This makes it possible to work between Windows and Linux. 11. Access Linux Files From Windows WSL also provides a way to access your Linux filesystem from Windows. From Windows File Explorer, you can enter: in the address bar. You should see your installed WSL distributions. For example: This allows Windows applications to interact with files inside your Linux environment. For development projects, however, it's generally best to keep Linux-oriented projects inside the Linux filesystem rather than constantly working across . 12. Install Development Tools Now you can use Linux normally. For example, install Git: Install GCC: Check GCC: Install Vim: Now you have a basic Linux development environment running inside Windows. Installing Another Distribution Later You can install multiple Linux distributions on the same Windows installation. For example: Then check them: You might have: You can start Debian with: Making a Distribution Your Default If you have multiple distributions installed, you can choose which one starts when you run: For example: Now: will start Debian by default. Useful WSL Commands Here are some commands you'll use frequently. List installed distributions List available distributions Start WSL Start a specific distribution Shut down WSL Stop a specific distribution Check WSL version Update WSL Set the default distribution Common Problems Doesn't Work First check whether WSL is available: Then try: You may also need to enable Windows virtualization features or restart Windows after enabling WSL. The Distribution Download Fails If you receive a network-related error while installing a distribution, check your internet connection first. You can also check the available distributions: Then retry the installation: Check Whether Virtualization Is Enabled Open Task Manager: Go to: Look for: If virtualization is disabled, you may need to enable the appropriate virtualization setting in your computer's UEFI/BIOS. WSL vs Dual Boot WSL and dual boot solve different problems. With dual boot, you install Windows and Linux as separate operating systems and choose one when the computer starts. With WSL, Linux runs alongside Windows. For development, WSL can be much more convenient because you don't need to reboot your computer every time you want to use Linux. A simple setup might look like: Conclusion Installing Linux with WSL is one of the easiest ways to get a Linux development environment on Windows. The basic workflow is: Then: Choose a distribution: Start it: And verify it: Once it's installed, you can use Linux tools, package managers, compilers, Git, editors, programming languages, and other development tools directly from Windows. Windows doesn't have to mean giving up the Linux development environment. With WSL, you can have both.

> 分享: