I want to install a specific version of npm (1.3.11). How can I do this? Is this even possible?
The npm docs explain how to install the latest version, but not a specific version.
You can suffix any NPM package with a specific version, including npm itself:
npm install npm#1.3.11 [-g]
(if you use -g, you will overwrite your currently installed version, which may or may not be your intention so be careful)
Related
When I did npm -v it showed version 7.something.
I just wanted to make sure I have the latest available, so I did npm install -g npm.
It seemed to work OK (it did go through a install/upgrade process) but when I now do npm -v it says 6.14.9.
What is the 'correct' or proper way to get the latest npm on macOS? And I mean in a global way (for my entire coding environment) so that any NodeJS project in any directory will universally use the latest npm.
FYI I'm using macOS Catalina 10.15.6.
npm 7 ships with Node.js 15.x but is not yet the default latest within the npm registry. Confusing! If you want the latest 7.x version of npm, you need to specify that you want version 7: npm install -g npm#7. Otherwise, it will give you the latest 6.x release.
I recommend using nvm to manage your node versions. It allows switching between projects with different versions without running into version issues.
With it, you can use nvm install node to install the latest one, or nvm ls-remote to list available versions for install.
I'm trying to learn node and npm, using express for a little project.
When i install it, i got
npm WARN deprecated core-js#2.6.10: core-js#<3.0 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js#3.
I understood that if everything works, it's not necessary to update everything, but i'm trying to learn and go the extra, unnecessary, mile.
How can i update only core-js?
npm install core-js#^3
will update it adding it to the dependencies in package.json.
Is this the right way to do it?
Or it's better to update the parent package that use it? If so, how can i understand which is the package that need an update and how to update it?
Or is there a way to update only the modules listed in package-lock.json.
Thanks.
You provided one way to update a package. However, there are a few more.
To update a global package, you could run:
npm update -g <package_name>
To update a package that's in your package.json (i.e., local to your project), run:
npm update <package_name>
You could also see what outdated package are there as follows:
npm outdated
You could again add -g option to check outdated global packages.
Sources: https://docs.npmjs.com/updating-packages-downloaded-from-the-registry
Also: man npm may help (in Linux).
To update to a new major version all the packages, install the npm-check-updates package globally:
npm install -g npm-check-updates
this will upgrade all the version hints in the package.json file, to dependencies and devDependencies, so npm can install the new major version.
You are now ready to run the update:
npm update
or npm install
My package depends on PackageA. PackageA depends on PackageB_Version2. I now need to install PackageC which depends on PackageB. How can I force npm to install that PackageC which is compatible with existing version of PackageB (i.e., PackageB_Version2)?
NPM will install a version specific packaging you tell it the version #. From the docs:
npm install [<#scope>/]<name>#<version>
npm install [<#scope>/]<name>#<version range>
So once you determine the version numbers and dependencies install with save to package.json and you will have your version dependencies saved until you update them.
I'm using NPM and shrinkwrap (latest up to date version) to maintain my packages.
At the moment, one of my package current version is 1.1.0.
The latest version of this package is 2.2.0.
I want to update/upgrade this specific package to version 2.0.0 (and not the latest 2.2.0).
I thought that the procedure would be:
npm install in order to make sure that I'm synchronized with the npm-shrinkwrap
npm update myPackage#2.0.0
npm shrinkwrap
git add . && git commit -m "Updating package myPackage to version 2.0.0"
This doesn't seem to be the right road to go. It doesn't update the package.json and it always jump to the latest version. I have no control over this command to select the specific version I want.
I read the documentation about npm update and couldn't find the proper way to update the package to a specific version.
How to do this ? Would npm install --save myPackage#2.0.0 would be the correct procedure ? Then what will be the purpose of having npm update command ?
Solution:
npm install package#2.0.0 --save
npm update doesn't seem to interact with the shrinkwrap file as far as I can tell. But you can use npm install to set the version of a package.
This will update both package.json and npm-shrinkwrap.json:
npm install myPackage#2.0.0 --save
You can enter to package.jsonand write the version yourself on the dependencies. After that do npm install and it will install the correct version.
Here is an example command for installing npm v2 instead of latest (which is v3):
npm install -g npm#latest-2
How does this syntax work?
Usually I use either latest or explicit version, but haven't seen such syntax before.
I've tried something similar with other packages, for example:
npm install express#latest-4
but it fails with error No compatible version found: express#latest-4
These are called tags, and they're intended to allow developers to label particular versions of their packages in a more human readable way.
By default, all versions are tagged as latest, but say you have a beta version that you want some users to test - rather than making them specify a particular version to install, you can tag your betas with npm publish --tag beta. This will then allow them to run npm install mypkg#beta to get the latest beta version.
You can also tag a version after you've already published by using npm dist-tag add <pkg>#<version> [<tag>].
See https://docs.npmjs.com/getting-started/using-tags for more info.