第一次写,没啥规划,随便记录的
系统 | 版本 |
---|---|
deepin | deepin-15.10.1-amd64 |
以下安装步骤都是在普通账户下操作 |
1. 安装zsh[重要]
# Deepin安装
sudo apt install zsh
# CentOS 安装
sudo yum update && sudo yum -y install zsh
2. 安装oh-my-zsh[重要]
- 此步骤前提必须配置git:Git - 安装配置(Linux、Windows双重记录)
你可以下载 install.sh,手动安装
备选方案:如果官网拒绝连接
,手动下载我的腾讯微云分享链:/linux/ohmyzsh
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh install.sh
或者 wget 自动下载安装
# wget 系统默认自带
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
或者 curl 自动下载安装
# curl 需要手动安装 sudo apt-get install curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
特别标注:
但是在国内,这两个网址由于众所周知的原因很难访问到,所以很难下载下来,所以我们可以替换成下面的脚本,其实就是把github的地址换成我们国内比较常用的gitee地址,gitee上的oh-my-zsh其实就是基于github做了一个镜像,所以内容完全一样。
sh -c "$(wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh -O -)"
sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
2.1 查看shell
- 查看当前使用shell
# nangy @ nangy-vm in ~ [14:09:24]
$ echo $SHELL
/bin/bash
- 查看系统中安装了哪些shell
# nangy @ nangy-vm in ~ [14:11:37]
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/usr/bin/dash
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/zsh
/usr/bin/zsh
2.2 切换默认shell[重要]
chsh -s /bin/zsh
2.3 .oh-my-zsh目录完全授权
如不授权,其他账户安装插件/使用主题,会报日志错误
如果只有一个常用账户的话,建议不用配置此步
否则后期不好git升级.oh-my-zsh
chmod -R 777 .oh-my-zsh
2.4 配置.zshrc文件
vim ~/.zshrc
2.4.1 跳过不安全目录的验证
- 非必要
# 放在配置文件最前面
ZSH_DISABLE_COMPFIX="true"
2.4.2 配置主题[重要]
- 查看有什么主题 - 官方主题演示
# nangy @ nangy-vm in ~ [13:48:24]
$ ls ~/.oh-my-zsh/themes
- 更改成自己想要的主题,我用的是ys,基本信息一步了然
# ZSH_THEME="robbyrussell"
ZSH_THEME="ys"
2.4.3 oh-my-zsh升级
更新时候出现如下报错,这是因为修改了oh-my-zsh的git文件
可以使用如下方式更新:
# nangy @ nangy-vm in ~ [9:56:36]
$ cd ~/.oh-my-zsh
# nangy @ nangy-vm in ~/.oh-my-zsh on git:master x [9:56:46] C:1
$ git status
# nangy @ nangy-vm in ~/.oh-my-zsh on git:master x [9:56:49]
$ git stash
# nangy @ nangy-vm in ~/.oh-my-zsh on git:master o [9:57:09] C:128
$ upgrade_oh_my_zsh
# nangy @ nangy-vm in ~/.oh-my-zsh on git:master x [9:57:09] C:128
$ git stash pop
2.4.3.1 关闭oh-my-zsh的自动更新
oh-my-zsh是个非常好用的工具,只要是在macOS、Linux下工作的同学们大多都会安装oh-my-zsh这个小工具,用来增强Terminal的功能。但是每天第一次打开Terminal的时候都会卡顿一下,原因是因为zsh每天会在第一次打开时进行自动更新检测。
# nangy @ nangy-vm in ~ [9:56:36]
$ vim ~/.zshrc
# 查找DISABLE_AUTO_UPDATE,将其注释打开,使其生效
# Uncomment the following line to disable bi-weekly auto-update checks.
DISABLE_AUTO_UPDATE="true"
- 如何手动更新呢
# nangy @ nangy-vm in ~ [9:56:36]
$ upgrade_oh_my_zsh
# 或者
# nangy @ nangy-vm in ~ [9:56:36]
$ zsh ~/.oh-my-zsh/tools/check_for_upgrade.sh
2.4.3 使.zshrc文件生效
# nangy @ nangy-vm in ~/Desktop [13:51:05]
$ source ~/.zshrc
- .zshrc 的最终内容
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/home/nangy/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="ys"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
!坑
1. root用户不生效???
普通用户安装后,切换到root用户下,居然没生效,所以呢,自己研究,丰衣足食
root根目下copy,再source居然报错,简单粗暴重启后居然有成功了,没明白
# root @ nangy-vm in ~ [13:56:14]
$ cp /home/nangy/.zshrc ~/
# root @ nangy-vm in ~ [13:56:37]
$ source ~/.zshrc
命令提示,而且还可以选择
2. 环境变量经常欠抽not find
so,弄了个临时解决方案
- 修改~/.zshrc,在末尾添加变量
例如:JAVA_HOME、SCALA_HOME、MAVEN_HOME
# nangy @ nangy-vm in ~ [13:47:12]
$ vim ~/.zshrc
- 再把修改后的.zshrc覆盖其他用户根目录的.zshrc
我这里只有root用户和自己工作用的普通用户,所以只复制一次就行
# nangy @ nangy-vm in ~ [13:51:45]
$ su
密码:
# root @ nangy-vm in ~ [13:55:46]
$ cp /home/nangy/.zshrc -R ~/
- 查看一下是否覆盖成功
# root @ nangy-vm in ~ [13:56:13]
$ tail ~/.zshrc
- 关闭终端重新打开,就可以每次都加载变量了
估计就是zsh的兼容坑吧,因为自己贪婪zsh的便捷,配置麻烦就麻烦吧,毕竟配置也就一次而已
以上着重记录一下,防止以后忘记了