0

作为 root,我在我的 OpenSUSE Leap 15.2 linux 服务器上删除了 /usr/local/bin 和 /usr/local/lib 中的一些目录,以清理一些 nodejs 模块。然后我卸载nodejsnpm使用 Zypper ( zypper remove nodejs npm)。我删除了根目录中的“.npm”目录。我find从 / 为 'node_modules' 做了一个,但没有找到。之后,我安装了“nodejs”和“npm”(zypper install nodejs npm),它报告它成功安装了它们。但是当我执行“npm -v”时,它会以/usr/local/bin/npm: No such file or directory. 我多次尝试卸载/重新安装这些软件包,但 npm 一直因此错误而失败。我有下面的输出。任何帮助是极大的赞赏。

The following 2 recommended packages were automatically selected:
  nodejs12-devel npm12

4 new packages to install.
Overall download size: 11.1 MiB. Already cached: 0 B. After the operation, additional 48.0 MiB will be used.
Continue? [y/n/v/...? shows all options] (y): y
Retrieving package nodejs-common-2.0-lp152.3.2.noarch                                                                          (1/4),   8.1 KiB (  230   B unpacked)
Retrieving: nodejs-common-2.0-lp152.3.2.noarch.rpm ...............................................................................................[done (5.2 KiB/s)]
Retrieving package nodejs12-12.18.2-lp152.3.3.1.x86_64                                                                         (2/4),   7.3 MiB ( 27.9 MiB unpacked)
Retrieving: nodejs12-12.18.2-lp152.3.3.1.x86_64.rpm ..............................................................................................[done (6.2 MiB/s)]
Retrieving package nodejs12-devel-12.18.2-lp152.3.3.1.x86_64                                                                   (3/4), 170.5 KiB (802.1 KiB unpacked)
Retrieving: nodejs12-devel-12.18.2-lp152.3.3.1.x86_64.rpm ........................................................................................[done (2.4 KiB/s)]
Retrieving package npm12-12.18.2-lp152.3.3.1.x86_64                                                                            (4/4),   3.6 MiB ( 19.3 MiB unpacked)
Retrieving: npm12-12.18.2-lp152.3.3.1.x86_64.rpm .............................................................................................................[done]

Checking for file conflicts: .................................................................................................................................[done]
(1/4) Installing: nodejs-common-2.0-lp152.3.2.noarch .........................................................................................................[done]
(2/4) Installing: nodejs12-12.18.2-lp152.3.3.1.x86_64 ........................................................................................................[done]
Additional rpm output:
update-alternatives: using /usr/bin/node12 to provide /usr/bin/node-default (node-default) in auto mode


(3/4) Installing: nodejs12-devel-12.18.2-lp152.3.3.1.x86_64 ..................................................................................................[done]
(4/4) Installing: npm12-12.18.2-lp152.3.3.1.x86_64 ...........................................................................................................[done]
Additional rpm output:
update-alternatives: using /usr/bin/npm12 to provide /usr/bin/npm-default (npm-default) in auto mode
update-alternatives: using /usr/bin/npx12 to provide /usr/bin/npx-default (npx-default) in auto mode


host1:/ # which npm
/usr/bin/npm
host1:/ # npm -v
-bash: /usr/local/bin/npm: No such file or directory
host1:/ # which node
/usr/bin/node
host1:/ # node -v
v12.18.2
host1:/ #
4

2 回答 2

0

尝试强制重新安装 node 和 npm 包。如果我没记错的话,你可以这样做:

$ zypper in -f $(rpm -qa nodejs* --qf '%{NAME} ')
$ zypper in -f $(rpm -qa npm* --qf '%{NAME} ')
于 2020-08-19T10:51:12.640 回答
0

我必须执行以下操作:

rm -rf node_modules
rm -rf package_lock.json

在它们安装的所有位置(请记住:npm 将它们安装在您执行的任何目录中npm install <module_name>)。find是 linux 上跟踪所有这些目录的有用命令。此外,我还必须删除.npm所有用户的目录(不仅仅是根用户)。完成这些然后重新安装 nodejs 和 npm 使用zypper成功。没有其他东西对我有用。祝你好运。

于 2020-08-20T00:43:24.163 回答