简体   繁体   English

如何卸载使用 npm 链接安装的 package?

[英]How do I uninstall a package installed using npm link?

When installing a node package using sudo npm link in the package's directory, how can I uninstall the package once I'm done with development?使用软件包目录中的sudo npm link安装节点 package 时,我如何在完成开发后卸载 package?

npm link installs the package as a symbolic link in the system's global package location ('/usr/local/lib`). npm link将 package 作为符号链接安装在系统的全局 package 位置('/usr/local/lib`)中。 This allows you to test the package while still developing it, without having to install it over and over again.这使您可以在开发 package 的同时对其进行测试,而无需一遍又一遍地安装它。

Which npm command do I need to run to remove the link again?我需要运行哪个 npm 命令才能再次删除链接?

The package can be uninstalled using the same uninstall or rm command that can be used for removing installed packages.可以使用可用于删除已安装包的相同卸载rm命令来卸载该包。 The only thing to keep in mind is that the link needs to be uninstalled globally - the --global flag needs to be provided.唯一要记住的是链接需要全局卸载 - 需要提供--global标志。

In order to uninstall the globally linked foo package, the following command can be used (using sudo if necessary, depending on your setup and permissions)为了卸载全局链接的foo包,可以使用以下命令(必要时使用sudo ,取决于您的设置和权限)

sudo npm rm --global foo

This will uninstall the package.这将卸载软件包。

To check whether a package is installed, the npm ls command can be used:要检查是否安装了包,可以使用npm ls命令:

npm ls --global foo

you can use unlink to remove the symlink.您可以使用unlink删除符号链接。

For Example:例如:

cd ~/projects/node-redis 
npm link                 
cd ~/projects/node-bloggy
npm link redis             # links to your local redis

To reinstall from your package.json:要从您的 package.json 重新安装:

npm unlink redis
npm install

https://www.tachyonstemplates.com/npm-cheat-sheet/#unlinking-a-npm-package-from-an-application https://www.tachyonstemplates.com/npm-cheat-sheet/#unlinking-a-npm-package-from-an-application

npm link pain: npm链接痛苦:

-Module name gulp-task - 模块名称gulp-task

-Project name project-x -项目名称project-x


You want to link gulp-task :你想链接gulp-task

1: Go to the gulp-task directory then do npm link this will symlink the project to your global modules 1:转到 gulp-task 目录,然后执行npm link这会将项目符号链接到您的全局模块

2: Go to your project project-x then do npm install make sure to remove the current node_modules directory 2:转到您的项目project-x然后执行npm install确保删除当前 node_modules 目录


Now you want to remove this madness and use the real gulp-task , we have two options:现在你想消除这种疯狂并使用真正的gulp-task ,我们有两个选择:

Option 1: Unlink via npm:选项 1:通过 npm 取消链接:

1: Go to your project and do npm unlink gulp-task this will remove the linked installed module 1:转到您的项目并执行npm unlink gulp-task这将删除链接的已安装模块

2: Go to the gulp-task directory and do npm unlink to remove symlink. 2:进入gulp-task目录并执行npm unlink以删除符号链接。 Notice we didn't use the name of the module注意我们没有使用模块的名称

3: celebrate 3:庆祝


What if this didn't work, verify by locating your global installed module.如果这不起作用怎么办,请通过定位您的全局安装模块进行验证。 My are location ls -la /usr/local/lib/node_modules/ if you are using nvm it will be a different path我的位置ls -la /usr/local/lib/node_modules/如果您使用的是nvm ,它将是不同的路径


Option 2: Remove the symlink like a normal linux guru选项 2:像普通的 linux guru 一样删除符号链接

1: locate your global dependencies cd /usr/local/lib/node_modules/ 1:找到你的全局依赖cd /usr/local/lib/node_modules/

2: removing symlink is simply using the rm command 2:删除符号链接只是使用rm命令

rm gulp-task make sure you don't have / at the end rm gulp-task确保最后没有/

rm gulp-task/ is wrong 🔥🚨 rm gulp-task/是错误的🔥🚨

rm gulp-task ✔️ rm gulp-task ✔️

npm uninstall --global my-package

If you've done something like accidentally npm link generator-webapp after you've changed it, you can fix it by cloning the right generator and linking that .如果您在更改后意外地执行了npm link generator-webapp 之类的操作,则可以通过克隆正确的生成器并链接来修复它。

git clone https://github.com/yeoman/generator-webapp.git;
# for fixing generator-webapp, replace with your required repository
cd generator-webapp;
npm link;

“npm install”用 npmjs 的版本(在 package.json 中指定)替换使用“npm link”安装的 node_modules 中的所有依赖项

You can undo the link command with the unlink command.可以使用unlink命令撤消link命令。

Create a link创建链接

In package包装内

cd ./some-package
npm link 

In comsumer消费类

cd ./some-project 
npm link some-package 

Remove a link删除链接

Removing a link should be done in the reverse order - start from the consumers.删除链接应该以相反的顺序完成 - 从消费者开始。

cd ./some-project 
npm unlink some-package 

In package包装内

cd ./some-package
npm unlink 

This worked for me:这对我有用:

  1. check the list of npm global packages:查看 npm 全局包列表:

    npm ls --global npm ls --global

  2. uninstall your package:卸载 package:

    npm uninstall --global my-package npm 卸载 --global my-package

  3. go to your testbed and unlink the linked package: go 到您的测试平台并取消链接链接的 package:

    npm unlink my-package npm 取消链接我的包

  4. navigate to your testbed directory and reinstall packages:导航到您的 testbed 目录并重新安装软件包:

    npm install npm安装

  5. restart your testbed server重新启动您的测试台服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM