如何在Windows 10上设置默认Linux发行版

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.exebash.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.

现在,当您运行wslbash命令时,将打开您选择Linux发行版。

Your default Linux distribution is also used when you run individual commands with either  wsl command or bash -c command.

当您使用wsl commandbash -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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值