修改$ PATH变量 [英] Modifying $PATH variable

查看:218
本文介绍了修改$ PATH变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试安装node.js.

Trying to install node.js.

没有brew install node

似乎有效.

但是,此消息在完成后收到

However, received this message upon its completion

Homebrew已安装npm.
我们建议将以下路径添加到您的PATH环境
变量以获取安装了npm的二进制文件:
/usr/local/share/npm/bin

Homebrew installed npm.
We recommend prepending the following path to your PATH environment
variable to have npm-installed binaries picked up:
/usr/local/share/npm/bin

好吧...所以,我打开我的bash_profile ...

Ok ... so, I open my bash_profile...

这就是我所拥有的:

 export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"

 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

试图了解如何正确修改它,这样我就不会破坏它……

Trying to understand how to modify it correctly so I won't ruin it ...

我是否这样添加/usr/local/share/npm/bin

export PATH="/usr/local/bin:/usr/local/sbin:~/bin/usr/local/share/npm/bin:$PATH"

如果没有,添加该路径的正确方法是什么?

If not, what is the correct way to add that path?

感谢您提供的任何帮助!

Thank you for any help provided!

PS.让我知道我是否可以提供其他信息

PS. let me know if there is any additional information I could have provided

编辑

在macedigital的答案中看到which npm时,我跑了那个……

upon seeing which npm in macedigital's answer, I ran that ...

得到了:/usr/local/bin/npm

那是在我做第二个答案(即ThiefMaster的答案)之前.

and that was before I did the second answer (ie, ThiefMaster's answer).

再次运行which npm ...

并且得到了与以前相同的答案...

and got the same answer as before ...

我确实回声了$PATH并且得到了:

i did echo $PATH and got this:

/Users/name/.rvm/gems/ruby-1.9.3-p374/bin:/Users/name/.rvm/gems/ruby-1.9.3-p374@global/bin:/Users/name/.rvm/rubies/ruby​​-1.9.3-p374/bin:/用户/名称/.rvm/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin: 〜/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin

/Users/name/.rvm/gems/ruby-1.9.3-p374/bin:/Users/name/.rvm/gems/ruby-1.9.3-p374@global/bin:/Users/name/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/name/.rvm/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin

那么,看来我已经安装了它?

So, it looks like I already had it installed?

因此,我该如何处理答案?我讨厌让它无法解决,因为你们俩都非常乐于助人,我很难过,我问我没有提供echo $PATH信息,因为那会告诉您我已经安装了它...

Therefore, how do I handle the answers? I hate leaving it unresolved since both of you were so helpful and I feel bad that I asked without providing echo $PATH information since that would have told you that I had it installed ...

编辑2

ls -la /usr/local/share/npm/bin获得此信息:

ls:/usr/local/share/npm/bin:没有这样的文件或目录

ls: /usr/local/share/npm/bin: No such file or directory

which -a npm收到此消息:/usr/local/bin/npm

编辑3

ls -a /usr/local/bin/npm收到此消息:/usr/local/bin/npm

没有时间戳...

推荐答案

简短回答,请执行此操作(注意我插入的其他冒号):

Short answer, do this (notice the additional colon I inserted):

export PATH="/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:$PATH"

如果要运行没有完全限定路径的命令(例如,运行npm而不是键入$PATH环境变量是用冒号分隔的目录列表. >).

The $PATH environment variable is colon separated list of directories to look in if you want to run a command without a fully qualified path (e.g. running npm instead of having to type /usr/local/share/npm/bin/npm).

您可以从终端尝试此操作,然后再将更改实际保存到bash_profile中.如果一切正常,which -a npm将为您显示所有完全合格的路径.

You can try this from a terminal before actually saving the change in bash_profile. If everything is good, which -a npm will show you all fully qualified path(s).

更新

使用npm不必修改$ PATH变量.相反,自制软件的建议是将存储npm安装的二进制文件的目录添加到$ PATH变量中,因此以后从命令行使用它们更加方便.

It is not necessary to modify the $PATH variable in order to use npm. What homebrew install recommends instead is to add the directory where npm-installed binaries are stored to the $PATH variables, so its more convenient to use them from the command line later on.

节点模块(例如phantomjs,phonegap,express等)提供了二进制文件,这些二进制文件在更改后可在命令提示符下使用,而无需键入完整路径.

Node modules like phantomjs, phonegap, express, etc. provide binaries which after the change are available on the command prompt without having to type the full path.

这篇关于修改$ PATH变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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