【问题标题】:Grunt installed on Ubuntu but not workingGrunt 安装在 Ubuntu 上但无法正常工作
【发布时间】:2015-09-18 22:12:28
【问题描述】:

我已经通过在终端中执行以下命令来安装 Grunt:

sudo apt-get install nodejs

sudo apt-get install npm

npm install -g grunt-cli

下面是执行npm install -g grunt-cli后的终端输出

npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/nopt
npm http 304 https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/glob
npm http 304 https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/lru-cache
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli@0.1.13 /usr/local/lib/node_modules/grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.7)
└── findup-sync@0.1.3 (lodash@2.4.2, glob@3.2.11)

应该全局安装 Grunt,但是当我在终端上尝试 grunt --version 时,它显示如下:

/usr/bin/env: node: No such file or directory

我尝试将 /usr/local/lib/node_modules/grunt-cli/bin 添加到 ~/.bashrc 中,但这没有帮助。

即使我尝试通过进入/usr/local/lib/node_modules/grunt-cli/bin 来执行grunt 命令,但没有希望。

请帮助我。

编辑: 这是sudo apt-get install nodejs的输出

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gyp javascript-common libc-ares-dev libjs-node-uuid libssl-dev libssl-doc
  libv8-3.14-dev rlwrap zlib1g-dev
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 261 not upgraded.
Need to get 0 B/684 kB of archives.
After this operation, 3,116 kB of additional disk space will be used.
Selecting previously unselected package nodejs.
(Reading database ... 172429 files and directories currently installed.)
Preparing to unpack .../nodejs_0.10.25~dfsg2-2ubuntu1_amd64.deb ...
Unpacking nodejs (0.10.25~dfsg2-2ubuntu1) ...
Processing triggers for doc-base (0.10.5) ...
Processing 1 added doc-base file...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up nodejs (0.10.25~dfsg2-2ubuntu1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode

这是来自/usr/local/binls -ln 的输出

lrwxrwxrwx 1 0 0 39 Jul  2 00:07 grunt -> ../lib/node_modules/grunt-cli/bin/grunt
lrwxrwxrwx 1 0 0 21 Jul  1 23:50 node -> /usr/local/bin/nodejs

【问题讨论】:

    标签: javascript node.js ubuntu gruntjs npm


    【解决方案1】:

    /usr/bin/env: node: No such file or directory 告诉你一切。当你apt-get install nodejs 我相信它会将nodejs 但不是node 放入你的/usr/local/bin。所以只需像符号链接一样

    sudo ln -s /usr/local/bin/nodejs /usr/local/bin/node
    

    它应该可以工作。

    编辑:应该是

    sudo ln -s /usr/bin/nodejs /usr/bin/node
    

    适合你的情况。

    【讨论】:

    • 当您安装 nodejs 时,我相信它会将 nodejs 而不是 node 放入您的 /usr/local/bin — 这取决于 如何 您安装它.我相信 Debian/Ubuntu 软件包就是这样做的。从官方来源安装它称为node
    • 是的,澄清了我的帖子。
    • @Patosai 我应该尝试 chris-lead 启动板而不是 Trusty saltycrane.com/blog/2014/11/how-install-grunt-ubuntu-1404
    • 或者更确切地说,您的安装日志显示它已安装到 /usr/bin/nodejs,所以只需从那里执行符号链接。
    • 您可以使用which nodejs 找到确切的路径。
    【解决方案2】:

    您还必须将 grunt 安装到您的项目文件夹中。 grunt-cli 包只是一个存根,它引用了位于项目的 node_modules 文件夹中的 grunt 包。

    npm install grunt

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 2011-12-18
      • 2017-10-05
      • 2015-02-05
      • 2015-03-26
      • 1970-01-01
      相关资源
      最近更新 更多