How to install a previous exact version of a NPM package?

node.jsNpm

node.js Problem Overview


I used nvm to download node v0.4.10 and installed npm to work with that version of node.

I am trying to install express using

npm install express -g

and I get an error that express requires node version >= 0.5.0.

Well, this is odd, since I am following the directions for a node+express+mongodb tutorial here that used node v0.4.10, so I am assuming express is/was available to node v0.4.10. If my assumption is correct, how do I tell npm to fetch a version that would work with my setup?

node.js Solutions


Solution 1 - node.js

If you have to install an older version of a package, just specify it

npm install <package>@<version>

For example: npm install [email protected]

You can also add the --save flag to that command to add it to your package.json dependencies, or --save --save-exact flags if you want that exact version specified in your package.json dependencies.

The install command is documented here: https://docs.npmjs.com/cli/install

If you're not sure what versions of a package are available, you can use:

npm view <package> versions

And npm view can be used for viewing other things about a package too. https://docs.npmjs.com/cli/view

Solution 2 - node.js

It's quite easy. Just write this, for example:

npm install -g npm@4.6.1

Or:

npm install -g npm@latest    // For the last stable version
npm install -g npm@next      // For the most recent release

Solution 3 - node.js

First remove old version, then run literally the following:

npm install express@3.X

or

npm install express@4.X

and for stable or recent

npm install -g npm@latest    // For the last stable version
npm install -g npm@next      // For the most recent release

Solution 4 - node.js

In my opinion that is easiest and fastest way:

$ npm -v

4.2.0

$ npm install -g npm@latest-3

...

$ npm -v

3.10.10

Solution 5 - node.js

npm install -g npm@version

in which you want to downgrade

npm install -g [email protected]

Solution 6 - node.js

you can update your npm package by using this command:

npm install <package_name>@<version_number>

example: npm install [email protected]

Solution 7 - node.js

You can use the following command to install a previous version of an npm package:

npm install packagename@version

Solution 8 - node.js

I have a general way to solve this type of problems, which could be helpful too, especially when cloning repositories to run them locally, but requires a little more analysis of the versions.

With the package npm-check-updates I verify the versions of the packages (according to the package.json file) that are not declared in their latest available versions, as shown in the figure (https://www.npmjs.com/package/npm-check-updates):

enter image description here

With this information we can verify the update status of the different packages and make decisions as to which packages to upgrade / degrade and which ones do not.

Assuming that we decided to update all the packages as they are listed, we can use the ncu -u command which only modifies your package.json file. Run npm install to update your installed packages and package-lock.json.

Then, depending on the requirements of the repository, we can refine what is needed, installing the specific versions with npm view <package> versions and npm install <package>@<version>

Solution 9 - node.js

If you have to install an older version of a package, just specify it

npm install @ For example: npm install [email protected]

You can also add the --save flag to that command to add it to your package.json dependencies, or --save --save-exact flags if you want that exact version specified in your package.json dependencies.

The install command is documented here: https://docs.npmjs.com/cli/install

If you're not sure what versions of a package are available, you can use:

npm view versions And npm view can be used for viewing other things about a package too. https://docs.npmjs.com/cli/view

Solution 10 - node.js

If you are using a mac, you can always use nvm and if windows, then you can use nodist

For window: https://changelog.com/posts/nodist-node-version-manager-for-windows

For Mac: https://github.com/nvm-sh/nvm

Solution 11 - node.js

The easiest way I found: add package name with the version in package.json and then run npm install

"next-seo": "^5.4.0",
"next-themes": "^0.1.1",
"nextjs-progressbar": "^0.0.14",

Solution 12 - node.js

Use npm config set save-exact=true if you want to install the exact version

Solution 13 - node.js

For yarn users:

yarn add package_name@version_number

Solution 14 - node.js

On Ubuntu you can try this command.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable 

Specific version : sudo n 8.11.3 instead of sudo n stable

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
Questionstewart99View Question on Stackoverflow
Solution 1 - node.jsBret CopelandView Answer on Stackoverflow
Solution 2 - node.jsinapsView Answer on Stackoverflow
Solution 3 - node.jsSaurabh Chandra PatelView Answer on Stackoverflow
Solution 4 - node.jsOleg BezkorovaynyiView Answer on Stackoverflow
Solution 5 - node.jsLakshay SharmaView Answer on Stackoverflow
Solution 6 - node.jsMehedi AbdullahView Answer on Stackoverflow
Solution 7 - node.jsPradeepaView Answer on Stackoverflow
Solution 8 - node.jsAlejandro AraujoView Answer on Stackoverflow
Solution 9 - node.jsabhishek singhView Answer on Stackoverflow
Solution 10 - node.jsOsama Ahmed TahirView Answer on Stackoverflow
Solution 11 - node.jsraqibnurView Answer on Stackoverflow
Solution 12 - node.jsArbër HyseniView Answer on Stackoverflow
Solution 13 - node.jsPeter MosesView Answer on Stackoverflow
Solution 14 - node.jsDeepti GehlotView Answer on Stackoverflow