【问题标题】:How to run this html-minifier from the command-line on Ubuntu?如何从 Ubuntu 的命令行运行这个 html-minifier?
【发布时间】:2018-02-26 05:22:30
【问题描述】:

我正在尝试从 Ubuntu 命令行运行 this HTML minifier。 但是当我尝试这样做时遇到了错误。

NodeJS 和 NPM 安装良好:

root$ apt-get install -y nodejs npm
Reading package lists... Done
Building dependency tree
Reading state information... Done
nodejs is already the newest version.
npm is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

安装 html-minifier 似乎可以工作:

root$ npm install html-minifier -g
npm http GET https://registry.npmjs.org/html-minifier
<... SNIP ...>
npm http 304 https://registry.npmjs.org/source-map
/usr/local/bin/html-minifier -> /usr/local/lib/node_modules/html-minifier/cli.js
html-minifier@3.5.9 /usr/local/lib/node_modules/html-minifier
├── commander@2.14.1
├── ncname@1.0.0 (xml-char-classes@1.0.0)
├── relateurl@0.2.7
├── he@1.1.1
├── param-case@2.1.1 (no-case@2.3.2)
├── camel-case@3.0.0 (upper-case@1.1.3, no-case@2.3.2)
├── clean-css@4.1.9 (source-map@0.5.7)
└── uglify-js@3.3.12 (source-map@0.6.1)

我可以看到已经安装了 html-minifier:

root$ which html-minifier
/usr/local/bin/html-minifier

root$ head -5 /usr/local/bin/html-minifier
#!/usr/bin/env node
/**
 * html-minifier CLI tool
 *
 * The MIT License (MIT)

但是当我尝试运行它时,我收到以下错误:

root$ html-minifier
/usr/bin/env: node: No such file or directory

为什么我不能运行 html-minifier?我究竟做错了什么?我该如何解决它??

【问题讨论】:

    标签: javascript node.js npm npm-install


    【解决方案1】:

    在 ubuntu 上,node 被称为 nodejs。我可以看到两个选项

    1. 编辑文件“/usr/local/bin/html-minifier”并将#!/usr/bin/env node更改为#!/usr/bin/env nodejs

    2. 添加一个小脚本node为你启动nodejs,或者试试alias node=nodejs

    【讨论】:

    • 或ln -s /usr/bin/nodejs /usr/bin/node。
    猜你喜欢
    • 2018-09-21
    • 2012-09-12
    • 1970-01-01
    • 2019-04-09
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    相关资源
    最近更新 更多