Windows Subsystem for Linux
近期发现Windows其实是可以直接运行Linux指令的,意味着我们不需要安装Linux系统,就可以学习Linux了。
Windows的指令与Linux、MacOS的指令是不一样的,我们可以通过在Windows上安装Git Bash来实现统一。近期发现微软已经主动去兼容其它系统的指令,即通过官方的Windows Subsystem for Linux(WSL)。
WSL官方的产品定位如下:
Windows Subsystem for Linux (WSL) lets developers run a GNU/Linux environment – including most command-line tools, utilities, and applications – directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.
安装WSL只需要运行以下一个指令:
wsl --install
运行完成之后需要设置用户名和密码,后期如果忘记密码是可以修改的,官方有提供相应的指导。安装好WSL后,运行Bash指令有以下两种方式:
- When you run
wsl -d ubuntu
, you launch the Ubuntu Linux shell inside WSL, which by default mounts the Windows file system drives (likeC:
under the/mnt
directory (e.g.,/mnt/c
). This allows you to interact with Windows files directly from the Ubuntu shell, blending access to both environments. - When you right-click PowerShell and select "Ubuntu GUI" (for example, Ubuntu from the Windows start menu or a shortcut that launches the Ubuntu GUI), it opens a graphical interface that operates directly inside the Ubuntu filesystem environment — typically under the WSL virtual filesystem like
/home/<user>
, which is distinct from the Windows filesystem. In this mode, you're primarily interacting with Ubuntu's native file system space, isolated from the Windows drives unless you explicitly navigate to/mnt/c
or other mounted locations.
Difference between Linux Shell and Linux GUI
wsl -d Ubuntu
(or justwsl
in PowerShell/CMD) is a command-line-first approach. When you run this command from a Windows terminal, it launches the WSL environment and places you in your Windows working directory. For instance, if you're in a PowerShell prompt atC:\Users\YourName\Documents
, runningwsl
will drop you into the Ubuntu shell at/mnt/c/Users/YourName/Documents
. This makes it very convenient for running Linux commands on files you've been managing with Windows tools.- Launching Ubuntu from the Start Menu is a separate process. This method launches Ubuntu in its native, isolated Linux environment. When it starts, it places you directly in the Linux home directory, which is
/home/yourusername/
. This is the ideal mode for developing with Linux tools and managing files that will be used exclusively within the Linux environment. Files in this directory are stored on the WSL virtual disk and perform better when accessed from the Linux side.
如果你想直接读写Windows驱动上的文件,可以直接运行Linux Shell in WSL;如果你想要一个完全独立的Linux系统,可以运行Linux GUI。