mac使用ZSH后的各种问题解决
- 1、安装maven 提示mvn command not found
- 分析
- 解决
- 2、.zshrc 文件不存在,vim默认是新建?
- 安装oh-my-zsh
- 配置.zshrc
- 3、什么brew 指令又command not found?
- 安装Homebrew
- 如果出现brew指令无法找到
- Homebrew基本使用
- 4、安装zsh-autosuggestion插件出现超时?
- 结语
1、安装maven 提示mvn command not found
分析
首先先要确定我们的mac电脑sell有哪种类型,通过以下命令查询
1 2 3 4 5 6 7 8 9 10 11 12 | cat /etc/shells # List of acceptable shells for chpass(1). # Ftpd will not allow users to connect who are not using # one of these shells. /bin/bash /bin/csh /bin/dash /bin/ksh /bin/sh /bin/tcsh /bin/zsh |
检查当前使用的sell:echo $SHELL
1 2 | echo $SHELL /bin/zsh |
切换zsh
1 | chsh -s /bin/zsh |
博主的默认为zsh,如果是bash,或许大家的环境变量是配置到个人 .bash_profile 文件中,而.bash_profile 默认是bash的配置,那么在转换zsh 过程中会导致mvn指令无法找到;
解决
1、将.bash_profile 的环境变量配置到 .zshrc ; 如果发现系统没有该配置文件,建议大家安装 oh-my-zsh,见下个问题
2、终端运行命令
1 | vim ~/.zshrc |
在配置文件末尾加入
1 | source ~/.bash_profile |
2、.zshrc 文件不存在,vim默认是新建?
博主mac 10.15.1 默认并不存在该文件,既然我们使用了zsh,那么推荐大家安装oh-my-zsh 插件,该插件非常强大,安装后会自动生成.zshrc 配置文件
安装oh-my-zsh
1 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" |
当看到 终端输出 oh my zsh 的标志,就代表安装成功了
配置.zshrc
1 | vim ~/.zshrc |
可以配置终端主题,配置对应插件 如:高亮 、自动补全、跳转目录等,具体可以到github查阅 点击前往
如果你用的是.bash_profile 做的环境变量配置,切记在末尾加上 source ~/.bash_profile,如博主的:
修改了.zshrc配置文件后 最后别忘了运行指令使其生效
1 | source ~/.zshrc |
3、什么brew 指令又command not found?
Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。
安装Homebrew
1 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
如果出现brew指令无法找到
网上有人是在.bash_profile 中配置 ,虽然也可以行
1 | export PATH=/usr/local/bin:$PATH |
但是实际上.zshrc 已经帮我们考虑到这一点,只需要解开这段注释即可:如图
再运行 brew -v 检查
1 2 3 | brew -v Homebrew 2.3.0 Homebrew/homebrew-core (git revision 4e40bd; last commit 2020-06-03) |
Homebrew基本使用
安装 和 卸载 指令
1 2 3 4 5 6 | brew install <packageName> brew uninstall <packageName> //如安装 node brew install node //如卸装 node brew uninstall node |
4、安装zsh-autosuggestion插件出现超时?
相信大家很多都是在网上查阅的安装,代码如下:
1 | git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions |
关键的问题在于 $ZSH_CUSTOM 这个变量值,查阅了github文档有说明
还是编辑 .zshrc 文件,将注释去除,按照默认提示博主设置如下:
再重新运行上述git 安装即可,安装完成后别忘了,再次设置 .zshrc 插件的启用哦
1 | plugins=(git zsh-autosuggestions) |
结语
以上是使用mac安装的一些常见问题,记录下来希望能帮助到大家~