如何卸载npm包? [英] How to uninstall npm package?

查看:209
本文介绍了如何卸载npm包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 sudo npm install grunt 安装了grunt,我无法删除它。

我'试试:

  $ sudo npm卸载grunt 

但它给WARN:

  npm WARN卸载未安装在/ home / kuba / projects / node_modules:grunt-cli

我也尝试了rm,remove和unlink 。和 -g 选项,它会给出:

  npm WARN uninstall not installed in / usr / lib / node_modules:grunt

但我仍然可以调用 grunt 来自命令行。



编辑

  $ whereis grunt 
grunt:/ usr / local / bin / grunt
$ file / usr / local / bin / grunt
/ usr / local / bin / grunt:符号链接到`../lib/node_modules/grunt/bin/grunt'
$ ls / usr / local / lib / node_modules
grunt jshint
$ ls / usr / lib / node_modules
bower csslint devtools-terminal npm plato

为什么我有2个目录NPM?删除它是否安全?

解决方案

要卸载 npm module from project node_modules 文件夹,运行:
$ b

npm卸载< module> --save



请注意, npm 模块应该从相同的目录中卸载包含运行此命令时的 node_modules 文件夹。 - save 选项也会将它从 package.json中删除



通过从本地 node_modules 文件夹中删除其目录,也可以删除本地依赖项/模块安装。是的,可以删除那里的依赖。



要卸载全局安装的 npm 模块,运行:



npm卸载-g< module>



无论您从何处运行此命令,都无关紧要。



安装 npm module,运行:(仅作为参考)

npm install< module>

...或者:

npm install (如果项目根目录下有 package.json 文件)



...或者:



npm install< module> --save-dev (如果你想添加一个最低版本的依赖)



关于的好消息> Grunt




  • 如果您安装了 grunt 2013年2月18日前保持稳定(当天 grunt v0.4.x 已经发布了),你可能会有一个旧的 grunt 版本仍然在你的系统中徘徊。这是因为全局安装了低于 0.4.x grunt 版本,这在升级/维护版本时造成了很大的痛苦。
  • grunt grunt-cli 是两件不同的事情。



    $ ul
    $ lt; code> grunt
    (没有cli)通常安装在项目中(通过运行 npm install 中的 devDependency package.json 中列出) code>。这也被称为本地安装

  • grunt-cli 是本地版本 grunt 在不同的项目/文件夹中运行。它可以在本地安装,但在全局安装时会更有用。


  • grunt 仅在本地安装(通过运行 npm install grunt )。 > npm install -g grunt-cli )。 grunt-cli 官方 npm 页面仍警告不要在全局安装 grunt (不含cli)。

  • 你想要卸载 grunt-cli 的全局安装,运行 npm uninstall -g grunt-cli 此问题 gruntjs 的项目支持此程序。 (通过运行 npm install -g grunt )。


    npm sudo



    sudo npm 中表现不佳。只有你必须使用它。下面是关于其使用的优点和缺点的两个引用:



    引用 Isaac Z. Schlueter 在他的 npm简介文章:


    鼓励你不要用sudo做包管理!
    软件包可以运行任意脚本,这可以使软件包管理器命令
    像链锯发型一样安全。当然,这是快速的,并且肯定会通过任何障碍来减少
    ,但是你可能真的希望这个障碍留在那里。



    我推荐这样做一次:

    sudo chown -R $ USER / usr / local



    这会将您的用户帐户设置为/ usr / local目录的所有者,以便您可以在
    中发出常规命令。然后,当您
    安装节点或发出npm命令时,您将无需使用sudo。



    这种方式更好。毕竟,/ usr / local应该是你安装的东西。


    Andrei Karpushonak


    有一些安全问题和关于将/ usr / local的所有权更改为当前用户的功能限制




    话虽如此,蚂蚁安装全球模块,而不使用sudo,
    我没有看到任何比提到的更好的解决方案(从实用的角度来看)。
    安全性vs易用性是一个非常广泛的话题,对于
    没有简单的答案 - 这取决于您的要求。

    I've installed grunt using sudo npm install grunt and I can't remove it.

    I've try:

    $ sudo npm uninstall grunt
    

    but it give WARN:

    npm WARN uninstall not installed in /home/kuba/projects/node_modules: "grunt-cli"
    

    I've also try rm, remove and unlink. and -g option, it give:

    npm WARN uninstall not installed in /usr/lib/node_modules: "grunt"
    

    but I still can call grunt from command line.

    EDIT:

    $ whereis grunt
    grunt: /usr/local/bin/grunt
    $ file /usr/local/bin/grunt
    /usr/local/bin/grunt: symbolic link to `../lib/node_modules/grunt/bin/grunt'
    $ ls /usr/local/lib/node_modules
    grunt jshint
    $ ls /usr/lib/node_modules
    bower  csslint  devtools-terminal  npm  plato
    

    Why I have 2 directories with npm? Is it safe to just delete it?

    解决方案

    To uninstall a npm module from project node_modules folder, run:

    npm uninstall <module> --save

    Note that npm modules should be uninstalled from the same directory that contains the node_modules folder when running this command. The --save option will also remove it from your package.json

    One can also remove a local dependency/module installation, by deleting its directory from the local node_modules folder. Yes, it's safe to delete dependencies there.

    To uninstall a npm module that was installed globally, run:

    npm uninstall -g <module>

    It doesn't matter where you run this command from.

    To install a npm module, run: (only meant as reference)

    npm install <module>

    ...or:

    npm install (if there's a package.json file at the root of your project)

    ...or:

    npm install <module> --save-dev (if you want to add a minimum version to the dependency)

    Good things to know about Grunt:

    • If you have installed grunt stable before February 18, 2013 (the day grunt v0.4.x was released), you might have an older grunt version still lingering in your system. That's because grunt versions lower than 0.4.x were installed globally, which caused a lot of pain when upgrading/maintaining versions.
    • grunt and grunt-cli are two different things.

      • grunt (without the "cli") is usually installed at the project level (when listed as a devDependency in package.json) by running npm install. That's also known as a local installation.
      • grunt-cli is the underlying foundation on which local versions of grunt run in different projects/folders. It can be installed locally, but is more useful when installed globally, once.
    • grunt is only installed locally (by running npm install grunt).

    • grunt-cli is preferably installed globally (by running npm install -g grunt-cli). grunt-cli official npm page still warns against installing grunt (without the cli) globally.
    • If you want to uninstall the global installation of grunt-cli, run npm uninstall -g grunt-cli. This issue on gruntjs's project supports this procedure.
    • Never install grunt globally (by running npm install -g grunt).

    On npm and sudo

    sudo doesn't play well with npm. Only use it if you must. Below are two quotes on the advantages and disadvantages on its use:

    Quoting Isaac Z. Schlueter on his Introduction to npm article:

    I strongly encourage you not to do package management with sudo! Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut. Sure, it's fast and definitely going to cut through any obstacles, but you might actually want that obstacle to stay there.

    I recommend doing this once instead:

    sudo chown -R $USER /usr/local

    That sets your user account as the owner of the /usr/local directory, so that you can just issue normal commands in there. Then you won't ever have to use sudo when you install node or issue npm commands.

    It's much better this way. /usr/local is supposed to be the stuff you installed, after all.

    Yet another catch mentioned by Andrei Karpushonak:

    There are certain security concerns and functionality limitations regarding changing the ownership of /usr/local to the current user:

    Having said that, if you want to install global module without using sudo, I don't see any better solution (from pragmatic point of view) than mentioned. Security vs easy of use is very broad topic, and there is no easy answer for that - it just depends on your requirements.

    这篇关于如何卸载npm包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆