How to list all versions of an npm package

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
2 min

banner

# How to list all versions of an npm package

Use the npm view <package> versions to list all versions of an npm package, e.g. npm view react versions.

The npm view <package> versions command shows the entire package version history for the specified package.

shell
npm view react versions # ๐Ÿ‘‡๏ธ alias for `npm view` npm show react versions

list all versions of npm package

Make sure to replace react with the name of your specific package.

You can use the --json flag to list the versions of the npm package as JSON.

shell
npm view react versions --json

If you use yarn, use the yarn info command to list all versions of an npm package.

shell
yarn info react versions

You can use the npm outdated command to list the current version and the latest version of your npm packages.

shell
npm outdated

You can use the npm view command to get the latest version of an npm package.

shell
npm view react version # ๐Ÿ‘‡๏ธ same as above npm show react version

npm show latest version of package

If you want to install the latest version of a package or update your currently installed package to the latest version, use the @latest modifier.

shell
npm install react@latest

install latest version of package

If you get an error when running the command, rerun it with the --legacy-peer-deps flag.

shell
npm install react@latest --legacy-peer-deps

If you need to update a global package to the latest version, use the -g flag.

shell
npm install -g create-react-app@latest

If you need to install a specific version of a package, use the @X.Y.Z modifier.

shell
npm install react@18.2.0

If you get an error when running the command, rerun it with the --legacy-peer-deps flag.

shell
npm install react@18.2.0 --legacy-peer-deps

If you need to check which version of a package is installed locally, use the npm ls <package> command.

shell
npm ls react # ๐Ÿ‘‡๏ธ without listing its dependencies npm ls react --depth=0

check which version of package is installed locally

Add the -g flag to the command to check which version of an npm package is installed globally.

shell
npm ls -g create-react-app

check which version of package is installed globally

You can use the npm outdated command to list the current version and the latest version of your npm packages.

shell
npm outdated

You can use the npm update command to update your locally installed packages or the npm update -g command to update your globally installed NPM packages.

shell
# ๐Ÿ‘‡๏ธ update ALL locally installed packages npm update # ๐Ÿ‘‡๏ธ update ALL globally installed packages npm update -g

The npm update command follows the version constraints specified in your package.json file.

If you want to update all packages in your project to the latest version, use the npm-check-updates package.

Open your terminal in your project's root directory (where your package.json file is) and run the following command.

You can add your package.json file to version control (e.g. git) because the following 2 commands will update the versions of your packages in your package.json file.
shell
npx npm-check-updates -u npm install --legacy-peer-deps

The commands update all package versions in your package.json file to the latest version and install the 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.

Copyright ยฉ 2024 Borislav Hadzhiev