在 Linux 上安装 Gulp - `npm install -g gulp` 不起作用?

Installing Gulp on Linux - `npm install -g gulp` doesn't work?

我正在尝试在我的计算机上全局安装 Gulp,但没有成功。我正在使用 Linux PopOs(Ubuntu,Debian)。

我已经完成了npm install -g gulp,输出是:

/home/ege/.npm/bin/gulp -> /home/ege/.npm/lib/node_modules/gulp/bin/gulp.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/gulp/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"a
ny"} (current: {"os":"linux","arch":"x64"})

+ gulp@4.0.2
updated 1 package in 14.336s

之后当我 运行 gulpgulp -v 命令时,我得到:

Command 'gulp' not found, but can be installed with:       

sudo apt install gulp 

然后我用 APT 包管理器安装了 Gulp: sudo apt install gulp 输出:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libbonobo2-0 libbonobo2-common libbonoboui2-0
  libbonoboui2-common libglade2-0 libgnome-2-0
  libgnome-keyring-common libgnome-keyring0
  libgnome2-common libgnomecanvas2-0
  libgnomecanvas2-common libgnomeui-0 libgnomeui-common
  libgnomevfs2-0 libgnomevfs2-common liborbit-2-0
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  gulp
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/11.1 kB of archives.
After this operation, 46.1 kB of additional disk space will be used.
Selecting previously unselected package gulp.
(Reading database ... 257257 files and directories currently installed.)
Preparing to unpack .../archives/gulp_3.9.1-6_all.deb ...
Unpacking gulp (3.9.1-6) ...
Setting up gulp (3.9.1-6) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

当我 运行 gulpgulp -v :

module.js:550
    throw err;
    ^

Error: Cannot find module 'gulp-util'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/lib/nodejs/gulp/bin/gulp.js:4:13)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)

我不明白发生了什么。 我知道 gulp-util 已被弃用,并且有一篇文章展示了如何使用 gutil 替换所有部件,但我什至没有使用 gulp,只是尝试 运行 命令并查看它是那里。

另外一个问题是,为什么通过 npm 安装它不起作用?

注意:我在全局安装了 gulp-cli。

除此之外,如果我删除通过 APT 包管理器安装的 gulp 和 运行 npx gulp -v,我可以看到 gulp 在那里...?! !??? 输出:

[15:18:30] CLI version 3.9.1
[15:18:30] Local version 3.9.1

有许多关于类似问题的未解决问题,但其中 none 对我有帮助。请帮忙..

一段时间后我找到了解决方案。这是关于 npm 的前缀来定义安装包的目录。 这里是 related post and the answer.