This article provides guidance on switching npm registry sources using npm config, npmrc file, and the --registry flag. It explains the benefits of using NRM for managing npm registries and NVM for handling npm source changes across different develop
There are several methods to switch npm registry sources:
Using the npm config command: Run the npm config command with the set registry flag, followed by the desired registry URL. For example, to switch to the npm public registry, run:
npm config set registry https://registry.npmjs.org/
Using the npmrc file: Create a .npmrc file in your home directory or project directory. Add the following line to the file, replacingyour-registry-url
with the desired registry URL:
registry=your-registry-url
Using the --registry flag: When running npm commands, you can use the --registry flag to specify the registry source. For example, to install a package from the npm public registry, run:
npm install --registry https://registry.npmjs.org/ @angular/core
NRM (Node Registry Manager) is a tool that allows you to manage multiple npm registries and easily switch between them. To use nrm, install it globally using npm:
npm install -g nrm
Once installed, you can use nrm to add, remove, or list registries. To add a registry, run:
nrm add
For example, to add the npm public registry, run:
nrm add public https://registry.npmjs.org/
To list the available registries, run:
nrm ls
To switch to a specific registry, run:
nrm use
To efficiently manage npm source changes across different development environments, it is recommended to use a tool like NVM (Node Version Manager). NVM allows you to install and manage multiple versions of Node.js on your system and easily switch between them. This way, you can have different development environments set up with different npm sources, allowing you to test and develop against specific registry configurations.
To use NVM, install it using the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Once installed, you can use NVM to install and manage different Node.js versions. To install a specific version, run:
nvm install 18.12.1
To switch to a different version, run:
nvm use 18.12.1
The above is the detailed content of npm switch source and nrm manage source. For more information, please follow other related articles on the PHP Chinese website!