最近看到有人推荐用oh my zsh,所以我也去配置了一下,其中踩了几个坑
My page after successful configuration
Think about these four questions for yourself
- What is zsh
- What is oh my zsh
- What are environment variables
- What is refresh variable
- Note: Read it again before installing
The above are when I stepped on the pit because I didn’t understand the concept
First of all, my macOS comes with zsh, if you still use bash, you can switch to zsh
You can check how many kinds of shells there are
cat /etc/shells
View the existing shells on the Mac.
Mine has seven types as follows
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
其中bash和zsh都是命令行的解释器工具,bash是我们最常见的shell(比如ubuntu自带bash),而zsh我也是最近才知道,我转zsh是因为自动补全和可配置一些好看的主题
The above shells are built-in on my mac, so you can directly switch to zsh (that is, use zsh to explain the commands we enter)
chsh -s /bin/zsh
Change to use zsh, enter the Mac password to confirm the change of shell type, exit the terminal, and re-enter.
enter
echo $SHELL
What is returned at this time is
/bin/zsh
, That is, you successfully converted to zsh.
What are environment variables?
If you have configured environment variables before, you may have used similar commands
source ~/.bash_profile # bash环境变量配置的文件
source ~/.zshrc # zsh环境变量配置的文件
So if you have configured the zsh environment variables, then you first
cat ~/.zshrc
Make a copy of these environments, because downloading oh my zsh will replace the contents in zshrc, so be sure to save it (we will configure the original environment variables after installing oh my zsh)
Install oh my zsh
为什么安装oh my zsh?,因为可以改变主题,比如加一些花里胡哨的样式或者你不喜欢旧的古板的样式主题,那么你可以去[oh my zsh 主题](https://github.com/ohmyzsh/ohmyzsh/wiki/themes)查看也没有自己喜欢的
PS:如果你以前配置过zsh环境变量,先把zshrc内容保存起来
curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
You should be like me at this time, you can’t connect
Failed to connect to raw.githubusercontent.com port 443: Connection refused
The problem is that the download source of github is contaminated, just like when we visit Google Facebook, it can’t be accessed anymore, so we can change to the real ip and let our connection directly access the real ip instead of accessing it. Fake IP on the wall.
The specific operation can be like this
在终端输入命令进入host文件中(Mac下)
sudo vi /etc/hosts
然后打开的文件 在最后一行加上
199.232.28.133 raw.githubusercontent.com
再按esc按键一下,然后输入 :wq 命令进行保存退出(:冒号要有)
In this way, when we visit the content of raw.githubusercontent.com, our computer will go directly to
199.232.28.133 to find the content we need.
Run it again next
curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
It succeeded
Configure theme
Open the zsh environment configuration file
vi ~/.zshrc
Find inside
ZSH_THEME="robbyrussell"
robbyrussell is the theme that comes with oh my zsh, you can also change it, the robbyrussell name is changed to the name of other favorite themes that you saw on the theme website just now
For example, I configure this location to
ZSH_THEME="apple"
The next step
is to configure the old environment variables back. My environment variables are all there ~/.bash_profile
, so I ~/.zshrc
configured these in the first line of the file:
export PATH=$HOME/bin:/usr/local/bin:$PATH
source $HOME/.bash_profile
That is, let zsh find the environment configuration in bash_profile, and associate and activate it
After saving our changes,
update our environment variable configuration
source ~/.zshrc
Exit the terminal and then open the terminal, and you will see the configured terminal.
Welcome to like my GitHub
Hi Caiji-Personal Homepage