How do I uninstall a package installed using npm link?

node.jsNpmNpm Link

node.js Problem Overview


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?

npm link installs the package as a symbolic link in the system's global package location ('/usr/local/lib`). This allows you to test the package while still developing it, without having to install it over and over again.

Which npm command do I need to run to remove the link again?

node.js Solutions


Solution 1 - node.js

The package can be uninstalled using the same uninstall or rm command that can be used for removing installed packages. The only thing to keep in mind is that the link needs to be uninstalled globally - the --global flag needs to be provided.

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)

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 --global foo

Solution 2 - node.js

you can use unlink to remove the symlink.

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:

npm unlink redis
npm install

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

Solution 3 - node.js

-Module name gulp-task

-Project name project-x


You want to link gulp-task:

1: Go to the gulp-task directory then do npm link this will symlink the project to your global modules

2: Go to your project project-x then do npm install make sure to remove the current node_modules directory


Now you want to remove this madness and use the real gulp-task, we have two options:

1: Go to your project and do npm unlink gulp-task this will remove the linked installed module

2: Go to the gulp-task directory and do npm unlink to remove symlink. Notice we didn't use the name of the module

3: celebrate


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


1: locate your global dependencies cd /usr/local/lib/node_modules/

2: removing symlink is simply using the rm command

rm gulp-task make sure you don't have / at the end

rm gulp-task/ is wrong 

rm gulp-task ✔️

Solution 4 - node.js

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.

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

Solution 5 - node.js

"npm install" replaces all dependencies in your node_modules installed with "npm link" with versions from npmjs (specified in your package.json)

Solution 6 - node.js

npm uninstall --global my-package

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnwinklerView Question on Stackoverflow
Solution 1 - node.jsnwinklerView Answer on Stackoverflow
Solution 2 - node.jsBlair AndersonView Answer on Stackoverflow
Solution 3 - node.jsKhaledMohamedPView Answer on Stackoverflow
Solution 4 - node.jsCode WhispererView Answer on Stackoverflow
Solution 5 - node.jsEugenioView Answer on Stackoverflow
Solution 6 - node.jsJulianSotoView Answer on Stackoverflow