How to Downgrade your NPM Version or a specific NPM package

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
4 min

banner

# Table of Contents

  1. Downgrade your version of NPM
  2. Downgrade the version of an installed NPM package

# Downgrade your version of NPM

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.

shell
npm --version

npm get 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.

shell
npm install -g npm@9.1.0

downgrade npm version

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.

If you don't specify the minor and patch versions, the latest major release gets installed.

For example, npm install -g npm@9 installs the latest major release of version 9.

shell
# 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.

shell
npm view npm versions --json

view available npm versions

You can use the npm --version command to verify if your version of npm has been downgraded.

shell
npm --version

verify npm version downgraded

# Dealing with permission issues

If you get a permissions error when running the npm install command on macOS or Linux, you have to prefix it with sudo.

shell
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:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

  1. Rerun the command after starting CMD as an administrator.
shell
npm install -g npm@9.1.0

# Downgrade the version of an installed NPM package

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.

shell
npm install express@4.12.3

npm downgrade express version

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.

shell
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.

shell
npm view express versions --json

check available versions of package

Make sure to replace express with your specific package.

# Downgrade the version of a globally installed NPM package

If you need to downgrade the version of a globally installed package, set the -g flag.

shell
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.

shell
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:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

  1. Rerun the command after starting CMD as an administrator.
shell
npm install -g create-react-app@5.0.1

You can verify the global package has been downgraded with the npm list -g command.

shell
npm list -g

verify global package downgraded

# Omitting the minor and patch versions

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.

shell
# 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.

version history of package

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.
I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.