【原创】Ubuntu 18.04.4 安装 oh-my-zsh

安装环境

1、版本信息

Ubuntu 18.04.4
apt 1.6.12
zsh 5.4.2

2、安装说明

本文档使用带有 sudo 权限的用户安装(不推荐使用 root 用户安装)

安装过程

1、更新 apt

sudo apt update

2、安装 zsh 依赖

sudo apt install -y zsh

3、安装 Oh My Zsh

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装示例:

jiangzl@MyInst-01:~$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Cloning Oh My Zsh...
Cloning into '/home/jiangzl/.oh-my-zsh'...
remote: Enumerating objects: 1152, done.
remote: Counting objects: 100% (1152/1152), done.
remote: Compressing objects: 100% (1117/1117), done.
remote: Total 1152 (delta 19), reused 1096 (delta 19), pack-reused 0
Receiving objects: 100% (1152/1152), 771.42 KiB | 3.27 MiB/s, done.
Resolving deltas: 100% (19/19), done.
Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc.
Time to change your default shell to zsh:
Do you want to change your default shell to zsh? [Y/n] y    # 此处输入 Y 将默认 shell 设置为 zsh 并继续
Changing the shell...
Password:    # 输入当前用户的密码
Shell successfully changed to '/usr/bin/zsh'.
.        __                                     __
. ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!
Please look over the ~/.zshrc file to select plugins, themes, and options.
p.s. Follow us on https://twitter.com/ohmyzsh
p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh

注:此处需要 Ubuntu 上已经安装 git,如果没有安装,请先安装 git

sudo apt install -y git

>>> 2020-11-11 更新开始

如果执行上面的命令官方给的一键安装命令时出现类似如下问题,表明你所有地区的 raw.github.com raw.githubusercontent.com 已经被墙了~

Failed to connect to raw.github.com port 443: Connection refused

有两种解决方法:

(1) 第一种就是使用 github 的镜像克隆

可以是自己私有的克隆,也可以是别人提供的公有的镜像,下面以公有镜像为例:

sh -c "$(curl -fsSLhttps://raw.staticdn.net/ohmyzsh/ohmyzsh/master/tools/install.sh)"

(2) 第二种就是先把源码克隆到本地,再本地化安装

在用户可读写的任意目录执行如下命令即可进行安装,基本等于一键安装。

git clone https://github.com/ohmyzsh/ohmyzsh; sh ohmyzsh/tools/install.sh

示例:

$ git clone https://github.com/ohmyzsh/ohmyzsh; sh ohmyzsh/tools/install.sh
Cloning into 'ohmyzsh'...
remote: Enumerating objects: 25383, done.
remote: Total 25383 (delta 0), reused 0 (delta 0), pack-reused 25383
Receiving objects: 100% (25383/25383), 7.18 MiB | 726.00 KiB/s, done.
Resolving deltas: 100% (12771/12771), done.
...
Cloning Oh My Zsh...
Cloning into '/Users/jiangzhuolin/.oh-my-zsh'...
remote: Enumerating objects: 1173, done.
remote: Counting objects: 100% (1173/1173), done.
remote: Compressing objects: 100% (1142/1142), done.
remote: Total 1173 (delta 19), reused 1091 (delta 15), pack-reused 0
Receiving objects: 100% (1173/1173), 807.79 KiB | 169.00 KiB/s, done.
Resolving deltas: 100% (19/19), done.
...
Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc.
...
         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!
...
...
Before you scream Oh My Zsh! please look over the ~/.zshrc file to select plugins, themes, and options.
...
• Follow us on Twitter: https://twitter.com/ohmyzsh
• Join our Discord server: https://discord.gg/ohmyzsh
• Get stickers, shirts, coffee mugs and other swag: https://shop.planetargon.com/collections/oh-my-zsh

建议使用第二种方法进行安装,因为第一种方法使用第三方提供的镜像不知道是否稳定,说不定哪天就不支持了,而自己从 github 同步到国内的 gitee 或者自己私有的 gitlab 源再进行安装,相对来说操作步骤多且繁琐。

综合来看,推荐使用第二种方法。

>>> 2020-11-11 更新结束。

4、安装 zsh-autosuggestions 插件

autosuggestions 是 zsh 的自动提示插件,可以自动提示已经输入过的命令,非常方便。此插件也可以不安装,但强烈建议安装

a、使用 git 下载 zsh-autosuggestions 插件到 ~/.oh-my-zsh/plugins 目录

cd ~/.oh-my-zsh/plugins
git clone git://github.com/zsh-users/zsh-autosuggestions

示例:

➜  plugins git:(master) cd ~/.oh-my-zsh/plugins
➜  plugins git:(master) git clone git://github.com/zsh-users/zsh-autosuggestions
Cloning into 'zsh-autosuggestions'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 2396 (delta 2), reused 3 (delta 1), pack-reused 2385
Receiving objects: 100% (2396/2396), 545.28 KiB | 481.00 KiB/s, done.
Resolving deltas: 100% (1533/1533), done.

b、配置 zsh-autosuggestions 插件

编辑 vi ~/.zshrc 文件,找到 plugins=(xxx) 这一行,添加 zsh-autosuggestions,如下示例

plugins=(git zsh-autosuggestions)

c、使用配置生效

source ~/.zshrc

5、将 shell 设置为 zsh,使用如下命令切换

正常情况下,安装成功 oh-my-zsh 后,会自动将 shell 切换到 zsh。

如果你在安装 oh-my-zsh 的时候没有选择切换 shell 到 zsh,那么你需要执行如下命令来切换。

chsh -s /bin/zsh

安装完成~

总结

1、安装校验

输入一个 git,已经提示了最近使用 git 的一条命令,只需要按一下方向键的右键即可完成此条命令的输入,非常方便:

2、卸载 oh-my-zsh

执行如下命令即可进行卸载。

uninstall_oh_my_zsh

如果执行上面的命令报错找不到 uninstall_oh_my_zsh,那么请你确保已经 source ~/.zshrc

附录

参考:

https://github.com/ohmyzsh/ohmyzsh

You may also like...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注