wsl
This commit is contained in:
198
raw/Home Office/Install WSL.md
Normal file
198
raw/Home Office/Install WSL.md
Normal file
@@ -0,0 +1,198 @@
|
||||
---
|
||||
title: "Install WSL"
|
||||
source: "https://learn.microsoft.com/en-us/windows/wsl/install"
|
||||
author:
|
||||
- "[[GrantMeStrength]]"
|
||||
published:
|
||||
created: 2026-04-18
|
||||
description: "Install Windows Subsystem for Linux with the command, wsl --install. Use a Bash terminal on your Windows machine run by your preferred Linux distribution - Ubuntu, Debian, SUSE, Kali, Fedora, Pengwin, Alpine, and more are available."
|
||||
tags:
|
||||
- "clippings"
|
||||
---
|
||||
#wsl #ubuntu #windows
|
||||
## How to install Linux on Windows with WSL
|
||||
|
||||
Developers can access the power of both Windows and Linux at the same time on a Windows machine. The Windows Subsystem for Linux (WSL) lets developers install a Linux distribution (such as Ubuntu, OpenSUSE, Kali, Debian, Arch Linux, etc) and use Linux applications, utilities, and Bash command-line tools directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 to use the commands below. If you are on earlier versions please see [the manual install page](https://learn.microsoft.com/en-us/windows/wsl/install-manual).
|
||||
|
||||
## Install WSL command
|
||||
|
||||
You can now install everything you need to run WSL with a single command. Open PowerShell in **administrator** mode by right-clicking and selecting "Run as administrator", enter the wsl --install command, then restart your machine.
|
||||
|
||||
PowerShell
|
||||
|
||||
```powershell
|
||||
wsl --install
|
||||
```
|
||||
|
||||
This command will enable the features necessary to run WSL and install the Ubuntu distribution of Linux. ([This default distribution can be changed](https://learn.microsoft.com/en-us/windows/wsl/basic-commands#install)).
|
||||
|
||||
If you're running an older build, or just prefer not to use the install command and would like step-by-step directions, see **[WSL manual installation steps for older versions](https://learn.microsoft.com/en-us/windows/wsl/install-manual)**.
|
||||
|
||||
The first time you launch a newly installed Linux distribution, a console window will open and you'll be asked to wait for files to de-compress and be stored on your machine. All future launches should take less than a second.
|
||||
|
||||
## Change the default Linux distribution installed
|
||||
|
||||
By default, the installed Linux distribution will be Ubuntu. This can be changed using the `-d` flag.
|
||||
|
||||
- To change the distribution installed, enter:
|
||||
```powershell
|
||||
wsl.exe --install [Distro]
|
||||
```
|
||||
Replace `[Distro]` with the name of the distribution you would like to install.
|
||||
- To see a list of available Linux distributions available for download through the online store, enter:
|
||||
```powershell
|
||||
wsl.exe --list --online
|
||||
```
|
||||
|
||||
If you run into an issue during the install process, check the [installation section of the troubleshooting guide](https://learn.microsoft.com/en-us/windows/wsl/troubleshooting#installation-issues).
|
||||
|
||||
To install a Linux distribution that is not listed as available, you can [import any Linux distribution](https://learn.microsoft.com/en-us/windows/wsl/use-custom-distro) using a TAR file. Or in some cases you can install using an `.appx` file. You can also create your own [custom Linux distribution](https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro) to use with WSL.
|
||||
|
||||
## Set up your Linux user info
|
||||
|
||||
Once you have installed WSL, you will need to create a user account and password for your newly installed Linux distribution. See the [Best practices for setting up a WSL development environment](https://learn.microsoft.com/en-us/windows/wsl/setup/environment#set-up-your-linux-username-and-password) guide to learn more.
|
||||
|
||||
## Set up and best practices
|
||||
|
||||
We recommend following our [Best practices for setting up a WSL development environment](https://learn.microsoft.com/en-us/windows/wsl/setup/environment) guide for a step-by-step walk-through of how to set up a user name and password for your installed Linux distribution(s), using basic WSL commands, installing and customizing Windows Terminal, set up for Git version control, code editing and debugging using the VS Code remote server, good practices for file storage, setting up a database, mounting an external drive, setting up GPU acceleration, and more.
|
||||
|
||||
## Check which version of WSL you are running
|
||||
|
||||
You can list your installed Linux distributions and check the version of WSL each is set to by entering the command:
|
||||
|
||||
PowerShell
|
||||
|
||||
```powershell
|
||||
wsl.exe --list --verbose
|
||||
```
|
||||
|
||||
To set the default version to WSL 1 or WSL 2 when a new Linux distribution is installed, use the command:
|
||||
|
||||
PowerShell
|
||||
|
||||
```powershell
|
||||
wsl.exe --set-default-version <1|2>
|
||||
```
|
||||
|
||||
To set the default Linux distribution used with the `wsl` command, enter:
|
||||
|
||||
PowerShell
|
||||
|
||||
```powershell
|
||||
wsl.exe --set-default <Distro>
|
||||
```
|
||||
|
||||
Replacing `<Distro>` with the name of the Linux distribution you would like to use. For example, from PowerShell, enter: `wsl -s Debian` to set the default distribution to Debian. Now running `wsl npm init` from Powershell will run the `npm init` command in Debian.
|
||||
|
||||
To run a specific wsl distribution from within PowerShell without changing your default distribution, use the command:
|
||||
|
||||
PowerShell
|
||||
|
||||
```powershell
|
||||
wsl.exe --distribution <DistroName>
|
||||
```
|
||||
|
||||
Replacing `<DistroName>` with the name of the distribution you want to use.
|
||||
|
||||
Learn more in the guide to [Basic commands for WSL](https://learn.microsoft.com/en-us/windows/wsl/basic-commands).
|
||||
|
||||
## Upgrade version from WSL 1 to WSL 2
|
||||
|
||||
New Linux installations, installed using the `wsl --install` command, will be set to WSL 2 by default.
|
||||
|
||||
To see whether your Linux distribution is set to WSL 1 or WSL 2, use the command: `wsl -l -v`. Upgrading from WSL 1 to WSL 2 or downgrading from WSL 2 to WSL 1 can be done using the following command:
|
||||
|
||||
PowerShell
|
||||
|
||||
```powershell
|
||||
wsl.exe --set-version <Distro> <1|2>
|
||||
```
|
||||
|
||||
Replacing `<Distro>` with the name of the Linux distribution that you want to update. For example, `wsl --set-version Ubuntu 2` will set your Ubuntu distribution to use WSL 2.
|
||||
|
||||
If you manually installed WSL prior to the `wsl --install` command being available, you may also need to [enable the virtual machine optional component](https://learn.microsoft.com/en-us/windows/wsl/install-manual#step-3---enable-virtual-machine-feature) used by WSL 2 and [install the kernel package](https://learn.microsoft.com/en-us/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package) if you haven't already done so.
|
||||
|
||||
To learn more, see the [Command reference for WSL](https://learn.microsoft.com/en-us/windows/wsl/basic-commands) for a list of WSL commands, [Comparing WSL 1 and WSL 2](https://learn.microsoft.com/en-us/windows/wsl/compare-versions) for guidance on which to use for your work scenario, or [Best practices for setting up a WSL development environment](https://learn.microsoft.com/en-us/windows/wsl/setup/environment) for general guidance on setting up a good development workflow with WSL.
|
||||
|
||||
## Ways to run multiple Linux distributions with WSL
|
||||
|
||||
WSL supports running as many different Linux distributions as you would like to install. This can include choosing distributions from the [Microsoft Store](ms-windows-store://collection?CollectionId=LinuxDistros), [importing a custom distribution](https://learn.microsoft.com/en-us/windows/wsl/use-custom-distro), or [building your own custom distribution](https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro).
|
||||
|
||||
There are several ways to run your Linux distributions once installed:
|
||||
|
||||
- [From Windows Terminal](https://learn.microsoft.com/en-us/windows/terminal/install) ***(Recommended)*** Using Windows Terminal supports as many command lines as you would like to install and enables you to open them in multiple tabs or window panes and quickly switch between multiple Linux distributions or other command lines (PowerShell, Command Prompt, Azure CLI, etc). You can fully customize your terminal with unique color schemes, font styles, sizes, background images, and custom keyboard shortcuts. [Learn more.](https://learn.microsoft.com/en-us/windows/terminal)
|
||||
- You can directly open your Linux distribution by visiting the Windows Start menu and typing the name of your installed distributions. For example: "Ubuntu". This will open Ubuntu in its own console window.
|
||||
- From PowerShell, you can enter the name of your installed distribution. For example: `ubuntu`
|
||||
- From PowerShell, you can open your default Linux distribution inside your current command line, by entering: `wsl.exe`.
|
||||
- From PowerShell, you can use your default Linux distribution inside your current command line, without entering a new one, by entering:`wsl [command]`. Replacing `[command]` with a WSL command, such as: `wsl -l -v` to list installed distributions or `wsl pwd` to see where the current directory path is mounted in wsl. From PowerShell, the command `Get-Date` will provide the date from the Windows file system and `wsl date` will provide the date from the Linux file system.
|
||||
|
||||
The method you select should depend on what you're doing. If you've opened a WSL command line within a PowerShell window and want to exit, enter the command: `exit`.
|
||||
|
||||
## Want to try the latest WSL preview features?
|
||||
|
||||
Try the most recent features or updates to WSL by joining the [Windows Insiders Program](https://www.microsoft.com/windowsinsider/getting-started). Once you have joined Windows Insiders, you can choose the channel you would like to receive preview builds from inside the Windows settings menu to automatically receive any WSL updates or preview features associated with that build. You can choose from:
|
||||
|
||||
- Canary Channel:
|
||||
- Ideal for highly technical users.
|
||||
- Preview the latest platform changes early in the development cycle.
|
||||
- These builds can be unstable and are released with limited to no documentation.
|
||||
- Dev Channel:
|
||||
- Ideal for enthusiasts.
|
||||
- Access the latest Windows 11 preview builds as we incubate new ideas and develop long lead features.
|
||||
- There will be some rough edges and low stability.
|
||||
- Beta Channel:
|
||||
- Ideal for early adopters.
|
||||
- Preview and provide feedback on pre-release features for Windows 11 in a stable environment.
|
||||
- Release Preview Channel:
|
||||
- Ideal if you want to preview fixes and certain key features, plus get optional access to the next version of Windows before it’s generally available to the world.
|
||||
- This channel is also recommended for commercial users.
|
||||
|
||||
If you prefer not switching your Windows installation to a preview channel, you can still test the latest preview of WSL by issuing the command:
|
||||
|
||||
PowerShell
|
||||
|
||||
```powershell
|
||||
wsl.exe --update --pre-release
|
||||
```
|
||||
|
||||
For more information check the [WSL Releases page on GitHub](https://github.com/microsoft/WSL/releases).
|
||||
|
||||
## Next Steps
|
||||
|
||||
Let's explore the basic commands of WSL next.
|
||||
|
||||
[Basic WSL commands](https://learn.microsoft.com/en-us/windows/wsl/basic-commands)
|
||||
|
||||
## Offline install
|
||||
|
||||
To install WSL offline, you need to do these steps:
|
||||
|
||||
- Download and install latest WSL MSI package from [the GitHub releases page](https://github.com/microsoft/wsl/releases)
|
||||
- Open a PowerShell window with admin privileges and run `dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart` to enable the Virtual Machine Platform optional component. You will likely need to restart your computer for this to take effect.
|
||||
- Install a distribution via a.wsl file. You can find URLs to download these files at [DistributionInfo.json](https://github.com/microsoft/WSL/blob/master/distributions/DistributionInfo.json) for your chosen distro.
|
||||
|
||||
## Additional resources
|
||||
|
||||
- [Windows Command Line Blog: Install WSL with a single command now available in Windows 10 version 2004 and higher](https://devblogs.microsoft.com/commandline/install-wsl-with-a-single-command-now-available-in-windows-10-version-2004-and-higher/)
|
||||
|
||||
---
|
||||
|
||||
## Additional resources
|
||||
|
||||
Training
|
||||
|
||||
Module
|
||||
|
||||
[Developing in the Windows Subsystem for Linux with Visual Studio Code - Training](https://learn.microsoft.com/en-us/training/modules/developing-in-wsl/?source=recommendations)
|
||||
|
||||
In this module, you learn how to use the Windows Subsystem for Linux (WSL) with Visual Studio Code (VS Code). We explore the installation process and the basics of using WSL. Additionally, we install and utilize the Visual Studio Code WSL extension. Finally, we demonstrate how to debug and run Python code in VS Code within our WSL environment.
|
||||
|
||||
Certification
|
||||
|
||||
[Microsoft Certified: Windows Server Hybrid Administrator Associate - Certifications](https://learn.microsoft.com/en-us/credentials/certifications/windows-server-hybrid-administrator/?source=recommendations)
|
||||
|
||||
As a Windows Server hybrid administrator, you integrate Windows Server environments with Azure services and manage Windows Server in on-premises networks.
|
||||
139
raw/Home Office/WSL2 启动与网络配置指南.md
Normal file
139
raw/Home Office/WSL2 启动与网络配置指南.md
Normal file
@@ -0,0 +1,139 @@
|
||||
---
|
||||
title: WSL2 启动与网络配置指南
|
||||
source:
|
||||
author: shenwei
|
||||
published:
|
||||
created:
|
||||
description:
|
||||
tags:
|
||||
---
|
||||
#wsl #ubuntu #windows
|
||||
# WSL2 启动与网络配置指南
|
||||
|
||||
## 一、 WSL2 基础启动操作
|
||||
|
||||
### 1. 首次安装与启用
|
||||
|
||||
- **快速安装命令**(管理员模式 PowerShell):
|
||||
|
||||
PowerShell
|
||||
|
||||
```
|
||||
wsl --install
|
||||
```
|
||||
|
||||
_注:默认安装 Ubuntu,完成后必须重启电脑。_
|
||||
|
||||
|
||||
### 2. 状态检查与版本转换
|
||||
|
||||
- **查看已安装分发版及状态**:
|
||||
|
||||
PowerShell
|
||||
|
||||
```
|
||||
wsl -l -v
|
||||
```
|
||||
|
||||
- **强制将分发版设置为 WSL2**:
|
||||
|
||||
PowerShell
|
||||
|
||||
```
|
||||
wsl --set-version <分发版名称> 2
|
||||
```
|
||||
|
||||
- **日常进入 Linux 终端**:
|
||||
|
||||
PowerShell
|
||||
|
||||
```
|
||||
wsl -d <分发版名称> # 启动指定版本
|
||||
wsl --shutdown # 强制停止所有运行中的 WSL 实例
|
||||
```
|
||||
|
||||
|
||||
## 二、 网络进阶配置(解决 GitHub/海外连接问题)
|
||||
|
||||
由于 WSL2 默认使用 NAT 模式,常会出现“localhost 代理无法镜像”或无法访问海外资源的情况。
|
||||
|
||||
### 1. 启用“镜像网络模式”(推荐方案)
|
||||
|
||||
这是最稳妥的方案,使 WSL2 与 Windows 共享网络堆栈。
|
||||
|
||||
- **操作步骤**:
|
||||
|
||||
1. 打开 Windows 用户目录(`C:\Users\<你的用户名>\`)。
|
||||
|
||||
2. 创建或编辑 `.wslconfig` 文件。
|
||||
|
||||
3. 写入以下配置:
|
||||
|
||||
Ini, TOML
|
||||
|
||||
```
|
||||
[wsl2]
|
||||
networkingMode=mirrored
|
||||
dnsTunneling=true
|
||||
firewall=true
|
||||
autoProxy=true
|
||||
```
|
||||
|
||||
4. 在 PowerShell 执行 `wsl --shutdown` 后重启 WSL。
|
||||
|
||||
|
||||
### 2. 手动配置终端代理
|
||||
|
||||
如果未开启镜像模式,需手动指向 Windows 宿主机 IP:
|
||||
|
||||
- **获取宿主机 IP**:`cat /etc/resolv.conf | grep nameserver`
|
||||
|
||||
- **设置临时变量**(假设端口为 7890):
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
export https_proxy="http://<宿主机IP>:7890"
|
||||
export http_proxy="http://<宿主机IP>:7890"
|
||||
```
|
||||
|
||||
|
||||
### 3. 使用国内镜像加速(针对 Hermes/uv 安装)
|
||||
|
||||
若 GitHub 访问受限,可使用代理地址:
|
||||
|
||||
- **手动安装 uv**:
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
curl -LsSf https://mirror.ghproxy.com/https://github.com/astral-sh/uv/releases/latest/download/uv-installer.sh | sh
|
||||
```
|
||||
|
||||
- **使用镜像安装 Hermes Agent**:
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
curl -fsSL https://mirror.ghproxy.com/https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash
|
||||
```
|
||||
|
||||
|
||||
## 三、 常见故障排查
|
||||
|
||||
- **错误码 Wsl/Service/WSL_E_VM_MODE_INVALID_STATE**:
|
||||
|
||||
- 通常由于虚拟化未开启或服务死锁。
|
||||
|
||||
- **解决**:检查 BIOS 中的 `Virtualization Technology` 是否为 `Enabled`;在 Windows 功能中勾选“虚拟机平台”。
|
||||
|
||||
- **文件权限问题**:
|
||||
|
||||
- 避免在 `/mnt/c/`(Windows 挂载目录)下执行复杂的 Linux 脚本安装。
|
||||
|
||||
- **建议**:始终先执行 `cd ~` 进入 Linux 原生家目录后再进行环境配置。
|
||||
|
||||
|
||||
---
|
||||
|
||||
_记录日期:2026-04-17_
|
||||
Reference in New Issue
Block a user