Last updated: Apr 4, 2024
Reading timeยท2 min
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.
npm view react versions # ๐๏ธ alias for `npm view` npm show react versions
react
with the name of your specific package.You can use the --json
flag to list the versions of the npm package as JSON.
npm view react versions --json
If you use yarn
, use the yarn info
command to list all versions of an npm
package.
yarn info react versions
You can use the npm outdated
command to list the current version and the
latest version of your npm
packages.
npm outdated
You can use the npm view
command to get the latest version of an
npm package
.
npm view react version # ๐๏ธ same as above npm show react version
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.
npm install react@latest
If you get an error when running the command, rerun it with the
--legacy-peer-deps
flag.
npm install react@latest --legacy-peer-deps
If you need to update a global package to the latest version, use the -g
flag.
npm install -g create-react-app@latest
If you need to install a specific version of a package, use the @X.Y.Z
modifier.
npm install react@18.2.0
If you get an error when running the command, rerun it with the
--legacy-peer-deps
flag.
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.
npm ls react # ๐๏ธ without listing its dependencies npm ls react --depth=0
Add the -g
flag to the command to check which version of an npm
package is
installed globally.
npm ls -g create-react-app
You can use the npm outdated
command to list the current version and the
latest version of your npm
packages.
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.
# ๐๏ธ 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.
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.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.