[英]How to uninstall global package with npm?
I have installed webpack in this way:我以这种方式安装了 webpack:
npm install -g webpack
Now want to uninstall it:现在想卸载它:
npm uninstall -g webpack
Check it again, it didn't been uninstalled:再次检查,它没有被卸载:
webpack -v
3.1.0
Why?为什么?
And, I use this way can't find webpack
:而且,我用这种方式找不到webpack
:
npm list -g | grep webpack
This also didn't work:这也不起作用:
npm uninstall -g webpack --save
After run this under a directory which included package.json
:在包含package.json
的目录下运行此命令后:
npm uninstall webpack
npm WARN babel-loader@6.4.1 requires a peer of webpack@1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.
npm WARN uglifyjs-webpack-plugin@0.3.1 requires a peer of uglify-js@^2.8.0 but none was installed.
npm WARN uglifyjs-webpack-plugin@0.3.1 requires a peer of webpack@^1.9 || ^2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.
Try running both of the below commands:尝试运行以下两个命令:
npm uninstall -g webpack
npm uninstall webpack
I think you might be checking/looking at the local version after deleting only the global one.我认为您可能会在仅删除全局版本后检查/查看本地版本。
You have to remove the packages manually installed globally on your os with sudo:您必须使用 sudo 删除在您的操作系统上手动安装的软件包:
On OsX navigate to this directory在 OsX 上导航到此目录
cd /usr/local/lib/node_modules
and和
sudo rm -rf <packageName> // sudo rm -rf webpack
npm uninstall -g webpack
为我工作,尝试在管理员模式下运行命令提示符。
You're most likely running a file from another install of npm.您很可能正在运行来自另一个 npm 安装的文件。
Run which webpack
to see where your shell is finding webpack.运行which webpack
以查看您的 shell 在哪里找到 webpack。
Run npm root -g
to find the root of the tree it's supposed to be in, being sure you're running the correct npm with npm -v
and which npm
.运行npm root -g
以找到它应该位于的树的根,确保使用npm -v
和which npm
。
If your webpack bin isn't in the npm root, reset your path to the webpack binary eg hash -d webpack
in bash, and then go remove the unwanted npm root from your PATH variable.如果您的 webpack bin 不在 npm 根目录中,请将您的路径重置为 webpack 二进制文件,例如 bash 中的hash -d webpack
,然后从 PATH 变量中删除不需要的 npm 根目录。 You can now use npm install -g webpack
and npm uninstall -g webpack
and it should work.您现在可以使用npm install -g webpack
和npm uninstall -g webpack
它应该可以工作。
I have tried uninstalling global packages in several ways.我尝试过以多种方式卸载全局包。
npm uninstall -g <package_name>
this didn't work. npm uninstall -g <package_name>
这不起作用。
I managed to remove the global packages in the following way:我设法通过以下方式删除了全局包:
npm list -g
运行这个命令npm list -g
C:\Users\user\AppData\Roaming\npm
)转到路径( C:\Users\user\AppData\Roaming\npm
)node_modules
find and delete the package转到node_modules
找到并删除包This should work.这应该有效。
YW!哟!
Try尝试
chown -R "$(whoami)": "$(npm root -g)"
(you may need sudo for it) and then npm uninstall -g again (你可能需要 sudo )然后再次 npm uninstall -g
If you are using Node Version Manager (nvm) and you want to remove a global system package you will need to switch to that version.如果您使用的是节点版本管理器 (nvm) 并且想要删除全局系统包,则需要切换到该版本。 For example:例如:
nvm use system
npm uninstall -g webpack
on windows run as administrator and run the command在 windows 上以管理员身份运行并运行命令
npm uninstall -g webpack
on Linux在 Linux 上
sudo npm uninstall -g webpack
In Windows, open the cmd with Administrator rights (start -> type cmd -> right-click on icon -> open with adm. rights), then navigate (in cmd type "cd ../../users/your_user_name") to your user folder, then run在 Windows 中,使用管理员权限打开 cmd(开始 -> 键入 cmd -> 右键单击图标 -> 使用管理员权限打开),然后导航(在 cmd 中键入“cd ../../users/your_user_name”)到您的用户文件夹,然后运行
npm uninstall -g webpack
or (I don't remember which one worked for me)或(我不记得哪一个对我有用)
npm uninstall webpack
You can try你可以试试
npm uninstall -g <name> --save
you can run in administrator mode on windows您可以在 Windows 上以管理员模式运行
for Linux适用于 Linux
sudo npm uninstall -g <name> --save
It worked for me on both它对我有用
Had the same issue an none of the answer above helped.有同样的问题,上面的答案都没有帮助。
My project was in a sub-directory of a larger project, which also had a node_modules folder.我的项目位于一个较大项目的子目录中,该项目也有一个 node_modules 文件夹。
That's why it says, something like "found another version higher in the tree."这就是为什么它说,类似“在树中找到更高版本的另一个版本”。
Delete that folder, go back to your sub-dir, remove node_modules and package-lock.json, and finally run npm install again.删除那个文件夹,回到你的子目录,删除 node_modules 和 package-lock.json,最后再次运行 npm install。
In archlinux, after running在archlinux中,运行后
npm uninstall -g <package_name>
you might have to manually enter /usr/lib/node_modules/ to remove the package's directory.您可能必须手动输入 /usr/lib/node_modules/ 以删除包的目录。 This will prevent conflicts if you try reinstalling that package with a different package manager like pacman.如果您尝试使用不同的包管理器(如 pacman)重新安装该包,这将防止冲突。
Building on @karthik006 's answer of deleting directly from the global node_module
folder, if you are using nvm, you first need to decide from which version of node you want to delete the global package.基于@karthik006 的直接从全局node_module
文件夹中删除的答案,如果您使用的是 nvm,则首先需要确定要从哪个版本的节点中删除全局包。
After that, switch to that version of node using nvm use <version>
之后,使用nvm use <version>
切换到该版本的节点
Then run nvm which current
to get the path where the executable for this version of node is saved.然后运行nvm which current
以获取保存此版本节点的可执行文件的路径。
The path will be something like <path to nvm node dir>/<node version>/bin/node
路径类似于<path to nvm node dir>/<node version>/bin/node
Using this path, cd into <path to nvm node dir>/<node version>/lib/node_modules
and then rm -rf
the packages that you want to remove.使用此路径, cd 进入<path to nvm node dir>/<node version>/lib/node_modules
然后rm -rf
要删除的包。
Try This:尝试这个:
npm uninstall -g <package_name>
E.g: npm uninstall -g webpack
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.