-
Locate the globally installed package or module: The
npm linkcommand is typically used to link a locally developed module to the global scope, enabling it to be used as if it were a published npm module during development. To uninstall this linked package, first identify its global location. The global node_modules directory is commonly found at/usr/local/lib/node_modulesor~/.npm-global/lib/node_modules. -
Remove the project-specific link: If you linked a package globally within a project using
npm link package-name, runnpm unlink package-namein the project directory to remove the link. This command eliminates the symbolic link to the global module from the project's node_modules directory. -
Uninstall the package globally: If you no longer need the package, execute
npm unlink -g package-nameornpm uninstall -g package-nameto remove it globally. This action deletes the package from the global node_modules directory.
For example, if you are developing a package named "example-package" and have linked it globally using npm link, follow these steps:
First, run the following command in any project directory that uses the package:
bashnpm unlink example-package
Then, remove the global link:
bashnpm unlink -g example-package
Alternatively, uninstall it globally directly:
bashnpm uninstall -g example-package
This approach ensures that development-time package links are properly cleaned up while preventing unnecessary packages from remaining in the global environment.