简体   繁体   中英

Installing multiple npm versions

Is it possible to install multiple versions of npm for different projects that I am working on or are the npm installations always global? (Windows 10)

Are also tried installing different versions with https://github.com/marcelklehr/nodist but it seems to affect only the node version, not the npm version.

Or does npm version actually matter? Can I just use the newest npm version even when a project says the requirement is a certain npm version?

You can install multiple versions of npm by installing multiple versions of node . To do this, you can use nvm-windows . Each different installation of node installs a different version of npm

To use a different version of node and nvm in a project, you simple need to switch:

nvm use 5.0

You can also create a .nvmrc file containing the version number in the project root directory. nvm will use the specified version of node for that project.

You also can install npm using npm

Example of installing specific version:

npm i -g npm@3.5.4

if you are using eclipse IDE for Node projects, you can easily change Node version using Webclipse plugin.

在此处输入图像描述

If you need to use a different version of npm for each project, there are a number of possible solutions. Probably the lightest-weight version is to use npx . A semi-common use-case for this can be projects that use lock-file v1 and another that uses lock-file v2. v2 was introduced in npm v7.

So in your project using lockfile v1, if you need to install a new package.

npx npm@v6 install dalle-node

For lockfile v2, or to just use the latest and great.

npx npm@latest install dalle-node

Or does npm version actually matter?

In most cases, it's not likely to matter much. The above example is one I run in to in my own projects. If you use a project and some of the npm commands are giving you trouble, eg npm run , try using the version of npm the project recommends before filing a bug with the maintainer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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