如何在Windows 10中使用Zsh(或其他Shell)

Ubuntu and the other Linux distributions available on Windows 10 use the Bash shell by default, but that’s not your only option. Windows has a compatibility layer for running Linux software on Windows, and you can use it to run Zsh or whatever shell you prefer.

Windows 10上可用的Ubuntu和其他Linux发行版默认情况下使用Bash shell,但这不是唯一的选择。 Windows具有用于在Windows上运行Linux软件的兼容性层,您可以使用它来运行Zsh或您喜欢的任何shell。

The Zsh shell now works on Windows 10. You can have Bash automatically execute Zsh whenever you launch it. Oh My Zsh also works for customizing your Zsh shell in Windows, just as it does in Linux.

Zsh Shell现在可以在Windows 10上运行。您可以在启动时让Bash自动执行Zsh。 就像MyLinux一样, My Zsh也可以在Windows中自定义Zsh Shell。

从安装Bash开始 (Start By Installing Bash)

Before installing your shell of choice, you’ll first need to enable the Windows Subsystem for Linux and install a Linux environment. We’ll be using Ubuntu as an example in this article, but you can perform a similar process on openSUSE and other Linux distributions.

在安装您选择的外壳之前,您首先需要为Windows启用Windows子系统并安装Linux环境。 本文将以Ubuntu为例,但是您可以在openSUSE和其他Linux发行版上执行类似的过程。

If you’ve already installed Bash on Windows, you’re good to go.

如果您已经在Windows上安装了Bash,那就很好了。

如何安装Zsh(或另一个Shell) (How to Install Zsh (or Another Shell))

After Bash is installed, you just need to install the shell you want to use from within Bash. You do this with the apt-get command, just as you’d install any other software package on Ubuntu Linux.

安装完Bash之后,您只需要从Bash中安装要使用的shell。 您可以使用apt-get命令执行此操作,就像在Ubuntu Linux上安装任何其他软件包一样。

To install Zsh on Ubuntu, open the Bash shell and run the following command:

要在Ubuntu上安装Zsh,请打开Bash shell并运行以下命令:

sudo apt-get install zsh

Press “y” when prompted, and then press Enter to continue. Apt-get automatically downloads and installs Zsh from Ubuntu’s repositories.

出现提示时按“ y”,然后按Enter继续。 Apt-get会从Ubuntu的存储库中自动下载并安装Zsh。

On other Linux distributions, just use your Linux distribution’s software installation command. For example, you’ll need to use the zypper command on openSUSE.

在其他Linux发行版上,只需使用Linux发行版的软件安装命令即可。 例如,您需要在openSUSE上使用zypper命令。

If you want to use another shell, specify the name of that shell instead of Zsh. For example, we’ve seen reports that the Fish shell also works well. To install it, you’d run the following command:

如果要使用其他外壳,请指定该外壳的名称而不是Zsh。 例如,我们已经看到有报道说Fish壳也可以很好地工作。 要安装它,您将运行以下命令:

sudo apt-get install fish

如何启动Zsh(或另一个Shell) (How to Launch Zsh (or Another Shell))

To launch Zsh or another shell after it’s installed, just type the name of the shell in the Bash prompt, and then press Enter. For example, to start using Zsh from Bash, you’d just type:

要在安装后启动Zsh或其他外壳,只需在Bash提示符下键入外壳的名称,然后按Enter。 例如,要开始从Bash使用Zsh,只需键入:

zsh

You’ll be prompted to go through Zsh’s first-time setup process and create a configuration profile the first time you launch it. Type “2” to create a configuration profile with the recommended default settings.

系统将提示您完成Zsh的首次设置过程,并在首次启动时创建配置文件。 键入“ 2”以使用推荐的默认设置创建配置文件。

To leave the zsh shell and return to Bash, just run the following command:

要离开zsh shell并返回到Bash,只需运行以下命令:

exit

如何直接启动Zsh (How to Directly Launch Zsh)

You can launch the Zsh shell directly with a command like the following:

您可以使用以下命令直接启动Zsh Shell:

wsl zsh
bash -c zsh
ubuntu -c zsh
opensuse-42 -c zsh
sles-12 -c zsh

如何使Bash自动启动Zsh (How to Make Bash Automatically Launch Zsh)

You can also have Bash automatically switch to Zsh whenever you launch it.

您还可以让Bash在启动时自动切换到Zsh。

To do this, you need to edit your .bashrc file. Bash runs the commands in this file every time it starts. You can make the edits using any text editor you like, including vi, but we’ll explain the process using nano.

为此,您需要编辑.bashrc文件。 Bash每次启动时都会在该文件中运行命令。 您可以使用任何喜欢的文本编辑器(包括vi)进行编辑,但我们将使用nano来解释该过程。

To open the .bashrc file in nano, run the following command:

要在nano中打开.bashrc文件,请运行以下命令:

nano .bashrc

Add the following lines to the file. You could simply add the “exec zsh” line, but the following additional lines ensure that Bash only launches Zsh when you open a Bash window. This avoid causing problems for other software.

将以下行添加到文件中。 您可以简单地添加“ exec zsh”行,但是以下附加行确保Bash仅在打开Bash窗口时启动Zsh。 这样可以避免引起其他软件的问题。

# Launch Zsh
if [ -t 1 ]; then
exec zsh
fi

If you wanted to execute a different shell, you’d enter that shell’s command instead of the “zsh” command.

如果要执行其他Shell,请输入该Shell的命令而不是“ zsh”命令。

After you make the changes, press Ctrl+O and then Enter to save the file. Press Ctrl+X to exit nano afterwards.

进行更改后,按Ctrl + O,然后按Enter保存文件。 然后按Ctrl + X退出nano。

Now, whenever you open the Ubuntu shortcut (or other Linux distribution shortcut) on Windows, it starts up with the Zsh shell.

现在,只要在Windows上打开Ubuntu快捷方式(或其他Linux发行版快捷方式),它就会以Zsh Shell启动。

To reverse your change, edit the .bashrc file again and delete the section you added.

要撤消更改,请再次编辑.bashrc文件,然后删除添加的部分。



All alternative Linux shells should work, in theory. If one doesn’t, Microsoft needs to fix the underlying Windows Subsystem for Linux so that is correctly runs more Linux software. You can view existing bugs and report new bugs to Microsoft at the BashOnWindows GitHub page.

从理论上讲,所有其他Linux外壳程序都应该起作用。 如果没有,则Microsoft需要修复Linux的基础Windows子系统,以便正确运行更多Linux软件。 您可以在BashOnWindows GitHub页面上查看现有错误并向Microsoft报告新错误。

翻译自: https://www.howtogeek.com/258518/how-to-use-zsh-or-another-shell-in-windows-10/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值