如何将 npm(node.js 包管理器)添加到 PATH?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6439036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I add npm (node.js package manager) to the PATH?
提问by emurad
I installed node.js like this:
我像这样安装了 node.js:
cd /usr/local/bin/
git clone --depth 1 http://github.com/joyent/node.git
cd node
git checkout origin/v0.4 # optional. Note that master is unstable.
export JOBS=2 # optional, sets number of parallel commands.
mkdir ~/local
./configure --prefix=$HOME/local/node
make
make install
echo 'export PATH=$HOME/local/node/bin:$PATH' >> ~/.profile
source ~/.profile
Then I executed this curl http://npmjs.org/install.sh | shto install npm. After I logged out and logged back in, npm command wasn't recognized:
然后我执行这个curl http://npmjs.org/install.sh | sh来安装npm。注销并重新登录后,无法识别 npm 命令:
[/usr/local/bin/node]# npm install now
-bash: npm: command not found
What should I add to the PATH to have npm working?
我应该在 PATH 中添加什么才能让 npm 工作?
回答by Thaddee Tyl
Try this:
尝试这个:
git clone https://github.com/npm/cli
cd npm/cli
sudo make install
That advice comes from of https://github.com/isaacs/npm#readme.
该建议来自https://github.com/isaacs/npm#readme。
It is not as cute as curl|sh, but works.
它不像 curl|sh 那样可爱,但有效。
回答by Calexo
Great news : npm now comes with nodejs !
好消息:npm 现在带有 nodejs!
回答by jinzi9800
I am a beginner~, but I want be helpful.
我是初学者~但我想对你有所帮助。
I use centos7, and do you know yum (a tool could download and setup programs like mirosoft Windows)
我用的是centos7,你知道yum吗(一个可以下载安装mirosoft Windows之类的程序的工具)
First, I search keyword "node.js" at wiki.centos, I find this. https://wiki.centos.org/SpecialInterestGroup/SCLo/CollectionsList?highlight=%28node.js%29. There are two versions of nodejs could be used at the moment, I chose the higher one. the URL is https://www.softwarecollections.org/en/scls/rhscl/rh-nodejs4/and the command lines are below:
首先,我在 wiki.centos 上搜索关键字“node.js”,我找到了这个。https://wiki.centos.org/SpecialInterestGroup/SCLo/CollectionsList?highlight=%28node.js%29。目前有两个版本的nodejs可以使用,我选择了较高的一个。URL 是https://www.softwarecollections.org/en/scls/rhscl/rh-nodejs4/,命令行如下:
# Install a package with repository for your system:
# On CentOS, install package centos-release-scl available in CentOS repository:
$ sudo yum install centos-release-scl-rh
# On RHEL, enable RHSCL repository for you system:
$ sudo yum-config-manager --enable rhel-server-rhscl-7-rpms
# 2. Install the collection:
$ sudo yum install rh-nodejs4
# 3. Start using software collections:
$ scl enable rh-nodejs4 bash

