【问题标题】:How can I add npm (node.js package manager) to the PATH?如何将 npm(node.js 包管理器)添加到 PATH?
【发布时间】:2011-09-20 07:24:51
【问题描述】:

我是这样安装 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

然后我执行了这个curl http://npmjs.org/install.sh | sh 来安装npm。在我注销并重新登录后,无法识别 npm 命令:

[/usr/local/bin/node]# npm install now
-bash: npm: command not found

我应该在 PATH 中添加什么以使 npm 正常工作?

【问题讨论】:

    标签: node.js centos cpanel whm


    【解决方案1】:

    试试这个:

    git clone https://github.com/npm/cli
    cd npm/cli
    sudo make install
    

    该建议来自https://github.com/isaacs/npm#readme

    它不像 curl|sh 那样可爱,但很管用。

    【讨论】:

    • 除了rm -rf /,圣诞节还有什么?
    • ASCII 艺术,很明显! (剧透警告,涉及 xterm 颜色)
    • 我得到这个:致命:无法连接套接字(连接超时)克隆“git://github.com/isaacs/abbrev-js.git”到子模块路径“node_modules” /abbrev' 失败 make: *** [子模块] 错误 1
    • 这很奇怪。你的网线拔掉了吗?
    • 不,我正在共享主机服务器上执行这些步骤,正常运行时间超过 100 天!
    【解决方案2】:

    我是初学者~,但我想对你有所帮助。

    我用centos7,你知道yum吗(一个工具可以下载和设置像mirosoft Windows这样的程序)

    首先,我在 wiki.centos 搜索关键字“node.js”,我找到了这个。 https://wiki.centos.org/SpecialInterestGroup/SCLo/CollectionsList?highlight=%28node.js%29。 目前可以使用的nodejs有两个版本,我选择了更高版本的。 网址是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
    

    【讨论】:

    • 我认为安装nodejs比手动安装更简单,祝你快乐!
    • 欢迎来到 Stack Overflow!我想指出,此时此特定帖子已有 6 年历史,并且已经接受了另一个答案,因此您的答案不太可能被很多人看到。
    【解决方案3】:

    好消息:npm 现在带有 nodejs!

    【讨论】:

    • 是的,但 nodenpm 仍然在 /usr/local/bin 中,我可以从终端运行 node 但不能运行 npm :(
    • 仍然没有从yum install nodejs安装
    猜你喜欢
    • 2016-06-16
    • 1970-01-01
    • 2021-04-26
    • 2014-09-15
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多