npm - how to show the latest version of a package
Asked Answered
S

10

434

How do I use npm to show the latest version of a module? I am expecting something like npm --latest express to print out v3.0.0.

Simulcast answered 14/8, 2012 at 9:27 Comment(1)
check a package's semantic version semver.npmjs.comAllstar
B
639

You can use:

npm view {pkg} version

(so npm view express version will return now 3.0.0rc3).

Beadledom answered 14/8, 2012 at 9:33 Comment(5)
npm view, npm show, npm info, and npm v all do the same thing.Upperclassman
this way involves loads poking around to find latest version, npm outdated seems to be the best wayAfresh
How can you show latest stable version. i.e. not beta versionSerrated
ah npm show {pkg} versions. version can be plural which will show all versions.Serrated
If only there was a way to check the versions of multiple packages like this in one bulk request to the registry. Is there?Divorcee
C
318

If you're looking for the current and the latest versions of all your installed packages, you can also use:

npm outdated

Camp answered 6/3, 2014 at 14:32 Comment(7)
I've looked at the whole post at least 5 times when I need to get the latest version of packages and I had never seen this, but it seems easier than running a number of other commands to check if you have libraries out of dateSabatier
to learn what the columns mean: https://mcmap.net/q/81899/-npm-wanted-vs-latestSidesaddle
a nice video explains how outdated and update work from NPM docs.npmjs.com/getting-started/updating-local-packagesTopdrawer
THIS IS THE MOST USEFUL! I wish npm update would just run this too - so I can at least see the latest versions. When you only run these commands once a month or so it's hard to remember all the options.Overlong
Except never mind - no it isn't. It shows me a completely blank column for latest, where I know some things have newer major versions :-/Overlong
Given how many users have found this answer helpful. Would it make sense to append this answer to the selected one?Stylography
this seems to just show outdated packages in a project, how to show outdated globally installed packages?Lindblad
D
102

As of October 2014:

npm view illustration

For latest remote version:

npm view <module_name> version  

Note, version is singular.

If you'd like to see all available (remote) versions, then do:

npm view <module_name> versions

Note, versions is plural. This will give you the full listing of versions to choose from.

To get the version you actually have locally you could use:

npm list --depth=0 | grep <module_name>

Note, even with package.json declaring your versions, the installed version might actually differ slightly - for instance if tilda was used in the version declaration

Should work across NPM versions 1.3.x, 1.4.x, 2.x and 3.x

Dripdry answered 3/10, 2014 at 7:28 Comment(3)
How would you get the last entry in npm view <module_name> versions?Cletus
npm view <module_name> versions command is very useful. + we can install a specific version of a package using npm install <module_name>@<version_number>Dunno
The last command, it's such an ugly and a challenging thing to remember. I wonder why they have not come up with a shorthand for that? for the local version or same as the other two, but with a -L (lowercase optional)?Pyrrolidine
C
16

You can see all the version of a module with npm view. eg: To list all versions of bootstrap including beta.

npm view bootstrap versions

But if the version list is very big it will truncate. An --json option will print all version including beta versions as well.

npm view bootstrap versions --json

If you want to list only the stable versions not the beta then use singular version

npm view bootstrap@* versions

Or

npm view bootstrap@* versions --json

And, if you want to see only latest version then here you go.

npm view bootstrap version
Chalybite answered 5/10, 2017 at 10:28 Comment(0)
H
11

The npm view <pkg> version prints the last version by release date. That might very well be an hotfix release for a older stable branch at times.

The solution is to list all versions and fetch the last one by version number

$ npm view <pkg> versions --json | jq -r '.[-1]'

Or with awk instead of jq:

$ npm view <pkg> versions --json  | awk '/"$/{print gensub("[ \"]", "", "G")}'
Hypertension answered 7/10, 2019 at 10:32 Comment(1)
I was in this exact case, and this answer was the most helpful to me! Thank you so much! Btw, you have a typo in the second example, you are missing the word versions before --jsonAcetate
C
6

This npm-check-updates package will help you to update and check the latest available package.

  • $ ncu Checking package.json
  • $ ncu -u Update all packages.
  • $ ncu -g Check global packages.

For more details check this link

https://www.npmjs.com/package/npm-check-updates

Chancellorship answered 2/5, 2021 at 4:19 Comment(1)
saves lot of time and effort! Thanks.Precipitin
A
5

There is also another easy way to check the latest version without going to NPM if you are using VS Code.

In package.json file check for the module you want to know the latest version. Remove the current version already present there and do CTRL + space or CMD + space(mac).The VS code will show the latest versions

image shows the latest versions of modules in vscode

Awn answered 15/10, 2018 at 9:38 Comment(2)
This does not work currently with the latest version of vscode.Kelson
@AchyutRastogi I am not sure why its not working for you. Its working fine in my VSCodeAwn
N
0

I just want to see the commithub current version and I find the way! Let's take a look together

npm list commithub version -g

This gives this output

/Users/hasan.tezcan/.nvm/versions/node/v14.18.0/lib
└── [email protected] 

But I just want to see the version in output

npm list --depth=0 commithub -g | awk '/commithub@/{gsub(/.*@/, "", $NF); print $NF}'

After that I can able to see only version that is amazing

0.0.1
Nemertean answered 2/3, 2023 at 23:43 Comment(0)
T
0
npm view express versions --json | grep -E '^ *"'\
  | sort -rV | head -n 1 | sed -E 's/^ *"(.+)",*$/\1/'

(currently 5.0.0-beta.1)

With major version specified:

npm view express versions --json | grep -E '^ *"4\.'\
  | sort -rV | head -n 1 | sed -E 's/^ *"(.+)",*$/\1/'

(currently 4.18.2)

With both major & minor specified:

npm view express versions --json | grep -E '^ *"3\.16\.'\
  | sort -rV | head -n 1 | sed -E 's/^ *"(.+)",*$/\1/'

(currently 3.16.10)

If you want to play around with these commands, you can start by dumping the JSON array of versions into a file: npm view express versions --json > express_versions.json.

Next, cat express_versions.json | grep -E '^ *"4\.' to see only the lines starting with zero or more spaces, followed by the string "4.

Next, cat express_versions.json | grep -E '^ *"3\.16\.' | sort -rV to see 3.16.x versions reverse-sorted using version sort.

Tack | head -n 1 onto that to show only the first line, in this case "3.16.10",.

Finally, | sed -E 's/^ *"(.+)",*$/\1/' strips "3.16.10", down to 3.16.10.

docs:
npm view
grep --extended-regexp (-E)
sort --reverse (-r)
sort --version-sort (-V)
head --lines (-n)
sed --extended-regexp (-E)

Thaine answered 15/11, 2023 at 21:42 Comment(0)
S
0
npm view @azure/static-web-apps-cli dist-tags.latest

Returns 1.1.6

Superconductivity answered 6/12, 2023 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.