【问题标题】:Did I mess up my PATH? .bash_profile我搞砸了我的路径吗? .bash_profile
【发布时间】:2018-10-26 21:00:48
【问题描述】:

我正在尝试使用atom 从我的终端打开文件。这导致了-bash: atom: command not found。然后我跟着编辑installing the shell commands。这导致了 "EEXIST: file already exists, mkdir '/usr/local/bin'" 。我之前曾尝试遵循其他关于如何添加 subl 别名的建议,我想我尝试了太多我不明白的事情。我能搞砸我的$PATH 吗?

当我回显我的路径时,这就是/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

我的 bash_profile 用 nano 打开时是这样的:

export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH export EDITOR='subl -w'

我不记得在尝试添加subl 时是否添加了第一行。

我应该删除它吗?我也在使用 MacOS High Sierra。

更新 我删除了之前在.bash_profile 中添加的内容,现在我的路径是:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

然后我运行了命令:sudo ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom,但得到了 ln: /usr/local/bin/atom: No such file or directory 错误

【问题讨论】:

  • 你试过'source .bash_profile'然后试试你的命令。
  • @jmh 刚刚尝试过。然后是 atom 和 subl 命令都找不到它们。
  • 通过键入 subl 来运行 sublime text 我的 .bash_profile 中有以下行: ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/ bin/subl
  • 尝试输入“哪个原子”,看看你会得到什么。可能什么都没有。
  • 我知道你有答案了。希望对你有帮助。

标签: bash macos path


【解决方案1】:

您可以从.bash_profile 中删除export PATH 语句;它不会添加任何不存在的东西。 (/usr/local/sbin 除外,但我会删除它,直到你证明需要它。)

最初,PATH 将包含/etc/path 中列出的目录:

% cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

您的任何 shell 配置文件都可以添加到 PATH。假设您没有对配置进行重大更改,/etc/profile 将运行 path_helper 以添加在 /etc/paths.d 下的文件中列出的所有目录。

如果您需要添加一个尚不存在的目录,您只需更新PATH。如果atom 位于上述路径之一,则无需执行任何操作。 听起来你试图在 /usr/local/bin 已经存在(应该)存在时创建它,然后可能最终没有在 /usr/local/bin 下创建 atom 的符号链接。

尝试仅从您链接的问题中运行ln 命令(如有必要,使用sudo),然后确认/usr/local/bin/atom 确实存在。

【讨论】:

  • 好的,我删除了 .bash_profile 中的内容,现在我的路径是 /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin。然后我运行了命令:` sudo ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom` 但得到了ln: /usr/local/bin/atom: No such file or directory 错误。 @chepner
  • 这很奇怪;听起来/usr/local/bin 不存在。 sudo mkdir -p /usr/local/bin 还会给你报错吗?
  • 是的。它说:mkdir: /usr/local/bin: Input/output error。我还按照here 的说明重置了我的$PATH,现在我的$PATH/usr/bin:/usr/sbin:/bin:/sbin
  • 好的,PATH 不是问题所在。问题是(无论出于何种原因)您无法创建指向atom.sh 的链接,该路径查找最终将在/usr/local/bin 中找到。
猜你喜欢
  • 2012-06-15
  • 1970-01-01
  • 2015-07-17
  • 1970-01-01
  • 1970-01-01
  • 2013-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多