Last updated: Apr 4, 2024
Reading time·4 min
You can use the npm install -g npm@<version>
command to downgrade the
version of NPM that is installed on your computer.
Make sure to specify the version number of the npm
package after the @
symbol in the command.
The npm
package can be downgraded in the same way as you would downgrade any
other package.
You can use the npm --version
command to get your version of npm
.
npm --version
For example, my version of npm
is 9.2.0
and I want to downgrade npm
to
9.1.0
, so I would issue the following command.
npm install -g npm@9.1.0
The -g
flag stands for global.
Notice that we specified the major, minor and patch versions when downgrading
NPM, e.g. npm install -g npm@major.minor.patch
.
For example, npm install -g npm@9
installs the latest major release of version
9
.
# installs the latest major release of version 9 npm install -g npm@9
You can use the npm view npm versions
command to print the available versions
of the npm
package.
npm view npm versions --json
You can use the npm --version
command to verify if your version of npm
has
been downgraded.
npm --version
If you get a permissions error when running the npm install
command on macOS
or Linux, you have to prefix it with sudo
.
sudo npm install -g npm@9.1.0
Make sure to specify the correct version of npm
you want to downgrade to.
If you get a permissions error on Windows when running the npm install
command, you have to open CMD as an administrator and rerun the command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
npm install -g npm@9.1.0
You can use the npm install <package>@<version>
command to downgrade the
version of an installed NPM package.
Make sure to specify the version number of the package you want to install
after the @
symbol in the command.
The syntax for downgrading your version of an installed NPM package is
npm install npm@<version>
where <version>
is the version number of the
package you want to install.
Here is an example of downgrading the express
package.
npm install express@4.12.3
Notice that we specified the major, minor and patch versions when downgrading
NPM, e.g. npm install express@major.minor.patch
.
If you get an error when running the command, try to use the --force
flag.
npm install express@4.12.3 --force
If you need to print the available versions of the package, use the
npm view <package> versions
command.
npm view express versions --json
Make sure to replace express
with your specific package.
If you need to downgrade the version of a globally installed package, set the
-g
flag.
npm install -g create-react-app@5.0.1
The -g
flag is used to install the package globally.
If you get a permissions error when running the npm install
command on macOS
or Linux, you have to prefix it with sudo
.
sudo npm install -g create-react-app@5.0.1
Make sure to specify the correct version of npm
you want to downgrade to.
If you get a permissions error on Windows when running the npm install
command, you have to open CMD as an administrator and rerun the command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
npm install -g create-react-app@5.0.1
You can verify the global package has been downgraded with the npm list -g
command.
npm list -g
If you don't specify the minor and patch versions, the latest major release gets installed.
For example, npm install express@3
installs the latest major release of
version 3
.
# installs the latest major release of version 3 npm install express@3
You can find the available versions of an NPM package in the versions tab of the package's NPM page.
Here is an example for Express.js.
If you need to check if the version of the package has been downgraded successfully, use the:
npm list
command for local packages.npm list -g
command for globally installed packages.