Downgrade npm to an older version - node.js

I tried updating npm to see if it would solve some dependency problems we were having, and now I want to downgrade to the version the rest of the development team is using. How can I install an older version?
I updated npm according to the instructions on the About npm CLI versions:
The latest release of npm
The latest release of npm is the most recent stable version. When you install Node.js, npm is automatically installed. However, npm is released more frequently than Node.js, so to install the latest stable version of npm, on the command line, run:
npm install npm#latest -g

Just replace #latest with the version number you want to downgrade to. I wanted to downgrade to version 3.10.10, so I used this command:
npm install -g npm#3.10.10
If you're not sure which version you should use, look at the version history. For example, you can see that 3.10.10 is the latest version of npm 3.

Just need to add version of which you want
upgrade or downgrade
npm install -g npm#version
Example if you want to downgrade from npm 5.6.0 to 4.6.1 then,
npm install -g npm#4.6.1
It is tested on linux

npm install -g npm#4
This will install the latest version on the major release 4, so no need to specify version number. Replace 4 with whatever major release you want.

Even I run npm install -g npm#4, it is not ok for me.
Finally, I download and install the old node.js version.
https://nodejs.org/download/release/v7.10.1/
It is npm version 4.
You can choose any version here
https://nodejs.org/download/release/

Related

nvm / node / npm: newer npm with node 12 than with node 14?

I'm using nvm to build libraries that require specific (different) Node versions.
When I do:
nvm use 12
I get:
Now using node v12.21.0 (npm v8.14.0)
But when I do:
nvm use 14
I get:
Now using node v14.18.1 (npm v6.14.15)
I'm very surprised to see an older npm version with a newer Node version. Is that the way it's supposed to be?
When I do nvm use 14 I'd expect it uses the latest Node 14.x with whatever latest npm version is available for that Node version. Or am I misunderstanding how this works?
Node.js is distributed with a version of npm, but npm is still a seperate package that can be upgraded.
The distributed versions can be retrieved from node release info
node npm
v12.22.12 6.14.16
v14.20.0 6.14.17
v16.17.0 8.15.0
v18.9.0 8.19.1
npm can prompt you to upgrade when it detects an old version, and you will also to run into this instruction in the wild a fair bit:
npm install -g npm
This will grab whatever the latest version of npm is and is likely what happened in the nvm 12 environment.
Sometimes moving to a new major version of npm can be a source of trouble for projects that have already been setup with a previous major npm release and some behaviour changes. CI tasks often have a npm install -g npm and one day they start falling over for what seems like no change. I've also seen npm drop support for an old version of node, so a npm install -g npm ends up with a broken npm.
If you want to keep a fixed major release, like v6 that Node 12 was release with, use:
npm install -g npm#^6
or to use a specific version
npm install -g npm#6.14.16

NPM stuck on an old version?

I was following some tutorial that was recorded a while ago, and it said for us to downgrade our npm version to 5.5.1 to avoid any differences (since that was the newest version at the time of the recording). So I did, using classic
npm install -g npm#5.5.1
However, now I'm stuck, I can't update to the actual present day latest version. I tried npm install -g npm#latest, I tried manually typing the latest version, I even tried uninstalling both Node and NPM, and installing the latest ones, fresh from the site, but for whatever reason my npm just gets stuck on 5.5.1 again. How do I fix this?
I'm using Windows btw. Also, I'm just learning about Node and NPM, so I guess there is a chance I'm missing some obvious solution?
Edit: whenever I try to install something, I get the following
npm WARN npm npm does not support Node.js v12.18.3
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6,
npm WARN npm You can find the latest version at https://nodejs.org/
WARNING: You are likely using a version of node-tar or npm that is incompa
with this version of Node.js.
Please use either the version of npm that is bundled with Node.js, or a ve
of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is compatible with
s 9 and above.
and after that a long list of errors, including, but not limited to
1: 000000013F8A5EBF napi_wrap+114095
2: 000000013F850B46 v8::base::CPU::has_sse+66998
3: 000000013F850EC1 v8::base::CPU::has_sse+67889
4: 000000013F78F187 RSA_meth_get_flags+85639
5: 000000014001AAE0 v8::internal::Builtins::builtin_handle+323456
try this
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
refer to this https://www.npmjs.com/package/npm-windows-upgrade or their GitHub repo for more help
if it doesn't help, try this
uninstall node (Settings -> Add or remove programs), then navigate to C:\Users\{User}\AppData\Roaming and delete the npm and npm-cache folder and finally install node again (using the installer).
You are missing the -g. You said:
I tried npm install npm#latest
but that that doesn't include the -g. The -g is key because it causes npm to be installed globally (best rhyme). See Downloading and installing packages globally. Your first command includes it, but not the follow up.
Because of this, you probably install npm as a local dependency (which you probably didn't mean to do). Check your package.json and see if there is any listing of npm. If you aren't directly using runtime pieces of npm, remove that dependency and just install the specific version you want globally with -g.
In your project root directory, run the update command:
npm update

installing custom npm version with nvm

I believe that all node versions are going to install a definite version of npm on your system - there is a 1 to 1 relationship between the node version and a npm version.
I am using nvm to install custom versions of node.
But how can I install a version of npm which is not the one - that is bundled with that version of node.
nvm install 8.17.0
nvm use 8.17.0
the npm version with it is 6.13.4 - But I want to use npm version of 5.6
How can I do that?
Is it possible to find the npm version which comes with various node versions?
Basically for installing the latest npm version is
npm install npm#latest
but how to do this
npm install npm#5.6
Got the answer:
npm install npm#5.6.0 -g

npm does not support Node.js v9.0.0

I just upgraded my project to use Node.js v9.0.0. When I start my project using npm, it tells me I should upgrade to a newer Node version, but I believe this is the newest version. I also believe I'm on the newest version of npm (5.5.1).
Do I need to worry about this warning? Is there a good way to resolve the issue?
Here's the full warning:
npm WARN npm npm does not support Node.js v9.0.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
Now using node v9.0.0 (npm v5.5.1)
I've just upgraded to Node v9 and ran into the same issue. There's a Github issue for this here.
Following the advice to uninstall a global instance of npm has resolved the issue for me, using:
npm uninstall -g npm
With Node 10.6.0 on Windows 10 with Git Bash installed, I did this and all worked well:
1. Launch Git Bash terminal.
2. cd ~/AppData/Roaming
3. rm -rf npm
4. rm -rf npm-cache
5. npm install -g npm#latest
Check version and test on an existing project to verify (cd to project dir)...
6. npm -version
7. npm install
NB: Performing steps 2 through 4 via Windows Explorer could be faster.
9.0.0 is indeed the latest version available at the moment. The reason that NPM shows you this message is because NPM hasn't updated their unsupported.js yet to accept 9.0.0 as a supported version.
I would say that you can probably use it without problems, but if you stumble upon one, know that it's probably caused by a breaking change in Node.js 9.0.0 and will very likely be fixed by the NPM team soon.
npm does not support Node.js v9.1.0
Uninstall did not work for me
npm uninstall -g npm
Node.js v9.1.0 comes bundled with npm v5.5.1. The latest version of npm is also v5.5.1, however, the version bundled with Node.js isn't exactly the same as the original version from npm.
The following is what I needed to do on MacOS
To completely uninstall node + npm, do the following:
1. go to /usr/local/lib and delete any node and node_modules.
2. go to /usr/local/include and delete any node and node_modules directory.
3. download and install node from nodejs.org
Latest update Jan 2018: NPM has released version 5.6.0 to work with this.
How to upgrade npm:
Note if you are using node version 9 you will not be able to upgrade npm directly, since npm does not support version 9, so using nvm, downgrade node to latest stable release, that will make npm work, then use commandnpm install -g npm#latest to upgrade npm.
Install nvm:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash\n
export NVM_DIR="$HOME/.nvm"\n[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Download and use node X version:
nvm install 4.4.2
nvm use 4.4.2
node -v
[sudo] npm install -g npm#5.3.x remove this problem for me. ubuntu 16.10

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

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?
If you have to install an older version of a package, just specify it
npm install <package>#<version>
For example: npm install express#3.0.0
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
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
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
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
you can update your npm package by using this command:
npm install <package_name>#<version_number>
example:
npm install yargs#12.0.2
You can use the following command to install a previous version of an npm package:
npm install packagename#version
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):
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>
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",
If you have to install an older version of a package, just specify it
npm install #
For example: npm install express#3.0.0
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
Use npm config set save-exact=true if you want to install the exact version

Resources