向 ZSH 中的 PATH 变量添加新条目 [英] Adding a new entry to the PATH variable in ZSH

查看:27
本文介绍了向 ZSH 中的 PATH 变量添加新条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 zsh 并且我正在尝试向 PATH 变量添加一个新条目 (/home/david/pear/bin) 但我没有不知道怎么做.

I'm using zsh and I'm trying to add a new entry (/home/david/pear/bin) to the PATH variable but I don't know how.

最让我困惑的是没有一个引用我的 ~/.zshrc 文件中的 PATH 变量,但执行 echo $PATH 返回:

The thing that confuses me the most is that there's not a single reference to a PATH variable in my ~/.zshrc file, but doing echo $PATH returns:

/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

因此在某处设置了 PATH 变量.

So a PATH variable is being set somewhere.

推荐答案

这里,在.zshrc中加入这一行:

Here, add this line to .zshrc:

export PATH=/home/david/pear/bin:$PATH

编辑:这确实有效,但是下面的ony 的答案更好,因为它需要ZSH 为诸如 $PATH 之类的变量提供的结构化接口的优势.这种方法是 bash 的标准,但据我所知,当 ZSH 提供更好的替代方案时,没有理由使用它.

EDIT: This does work, but ony's answer below is better, as it takes advantage of the structured interface ZSH provides for variables like $PATH. This approach is standard for bash, but as far as I know, there is no reason to use it when ZSH provides better alternatives.

这篇关于向 ZSH 中的 PATH 变量添加新条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆