
Windows 10 now allows you to install multiple Linux environments, starting with the Fall Creators Update. If you have multiple Linux environments, you can set your default and switch between them.
Windows 10現在允許您從Fall Creators Update開始安裝多個Linux環境。 如果您有多個Linux環境,則可以設置默認值并在它們之間切換。
You’re free to run multiple Linux environments at once, but your default environment is used when you run a command like wsl.exe
or bash.exe
to launch the shell, or when you use wsl [command]
or bash -c [command]
to run a command from elsewhere in Windows.
您可以自由地一次運行多個Linux環境,但是當您運行諸如wsl.exe
或bash.exe
類的命令來啟動Shell時,或者當您使用wsl [command]
或bash -c [command]
wsl [command]
時,將使用默認環境。 bash -c [command]
從Windows的其他位置運行命令。
如何設置默認Linux發行版 (How to Set Your Default Linux Distribution)
The wslconfig.exe
command lets you manage the Linux distributions running via the Windows Subsystem for Linux, or WSL.
wslconfig.exe
命令使您可以管理通過Windows Subsystem for Linux或WSL運行Linux發行版。
To run it, you need to open either a Command Prompt or PowerShell window. To open a Command Prompt window, open the Start menu, type “cmd”, and then click the “Command Prompt” shortcut. To open a PowerShell window, right-click your Start button (or press Windows+X), and then select the “Windows PowerShell” command.
要運行它,您需要打開命令提示符或PowerShell窗口。 要打開命令提示符窗口,請打開“開始”菜單,鍵入“ cmd”,然后單擊“命令提示符”快捷方式。 要打開PowerShell窗口,請右鍵單擊“開始”按鈕(或按Windows + X),然后選擇“ Windows PowerShell”命令。
To view your installed Linux distributions, type the following command and hit Enter:
要查看已安裝Linux發行版,請鍵入以下命令,然后按Enter:
wslconfig /l
The Linux distribution ending with “(Default)” is your default Linux distribution.
以“(默認)”結尾Linux發行版是您的默認Linux發行版。
If you don’t see an installed Linux distribution in this list, you’ll first need to launch it. Wait for the “Installing, this may take a few minutes…” process to complete. When it’s done, the Linux distribution will appear in this list.
如果在此列表中沒有看到已安裝Linux發行版,則首先需要啟動它。 等待“安裝,這可能需要幾分鐘……”過程完成。 完成后,Linux發行版將出現在此列表中。

To set your default Linux distribution, run the following command, where Name is the name of the Linux distribution:
要設置默認Linux發行版,請運行以下命令,其中Name是Linux發行版的名稱:
wslconfig /setdefault Name
For example, to set Ubuntu as your default Linux distribution, run the following command:
例如,要將Ubuntu設置為默認Linux發行版,請運行以下命令:
wslconfig /setdefault Ubuntu

Now, when you run either the wsl
or bash
commands, the Linux distribution you selected opens.
現在,當您運行wsl
或bash
命令時,將打開您選擇Linux發行版。
Your default Linux distribution is also used when you run individual commands with either? wsl command
or bash -c command
.
當您使用wsl command
或bash -c command
運行單個命令時,也會使用默認Linux發行版。

如何運行多個Linux發行版 (How to Run Multiple Linux Distributions)
You can run a Linux environment even if it isn’t your default. For example, you can launch the Ubuntu, openSUSE Leap, and SUSE Linux Enterprise Server shortcuts from your Start menu and you’ll have all three separate environments running at the same time.
即使不是默認環境,您也可以運行Linux環境。 例如,您可以從“開始”菜單中啟動Ubuntu,openSUSE Leap和SUSE Linux Enterprise Server快捷方式,并且您將同時運行所有三個單獨的環境。

To launch a Linux distribution from the command line or via a shortcut, just use its command. The command you need is displayed on the Linux distribution’s page in the Microsoft Store. Here are the commands you’ll need to? launch the three initial three Linux distributions:
要從命令行或通過快捷方式啟動Linux發行版,只需使用其命令即可。 所需的命令顯示在Microsoft StoreLinux發行版頁面上。 這是啟動三個最初的三個Linux發行版所需的命令:
Ubuntu:
ubuntu
Ubuntu的:
ubuntu
openSUSE Leap 42:
opensuse-42
openSUSE飛躍42:
opensuse-42
SUSE Linux Enterprise Server 12:
sles-12
SUSE Linux Enterprise Server 12:
sles-12
For example, even if Ubuntu is your default environment, you can still launch openSUSE from anywhere by running the opensuse-42
command.
例如,即使Ubuntu是您的默認環境,您仍然可以通過運行opensuse-42
命令從任何地方啟動openSUSE。

These commands also work with the same -c
switch you can use with the bash.exe
command. Just use the below command structure, where “distro-command” is the same command you use to launch the Linux distribution and “command” is the Linux command you want to run.
這些命令還可以與可以與bash.exe
命令一起使用的-c
開關一起使用。 只需使用以下命令結構,其中“ distro-command”是用于啟動Linux發行版的命令,而“ command”是您要運行Linux命令。
distro-command -c command
In other words, even if openSUSE Leap is your default Linux distribution, you can still run a command on Ubuntu from a command-line environment or script just by running ubuntu -c command
.
換句話說,即使openSUSE Leap是您的默認Linux發行版,您仍然可以僅通過運行ubuntu -c command
環境或腳本在ubuntu -c command
運行ubuntu -c command
。
For example, to run the apt-get moo
command that shows an Easter egg on Ubuntu, you’d run the following command:
例如,要在Ubuntu上運行顯示復活節彩蛋的apt-get moo
命令,請運行以下命令:
ubuntu -c apt-get moo

翻譯自: https://www.howtogeek.com/344688/how-to-set-your-default-linux-distribution-on-windows-10/