npm version, dist-tags & deprecate
Publishing once is easy. Releasing well over time takes three more tools: npm version bumps the version consistently (and tags git), dist-tags control what npm install pkg means, and npm deprecate warns users away from a release without breaking anyone who depends on it.
npm version
npm version <major|minor|patch|premajor|preminor|prepatch|prerelease|x.y.z> updates package.json and the lockfile, and in a git repository it also commits and tags:
mkdir -p lib && cd lib && git init -q
echo '{ "name": "@learner/lib", "version": "1.4.2", "main": "index.js" }' > package.json
echo 'module.exports = 1;' > index.js
git add -A && git commit -qm "initial"
npm version patch
npm version minor -m "release %s"
npm version prerelease --preid rc
git log --oneline
git tag
npm version 2.0.0 --no-git-tag-version
git status --shortv1.4.3
v1.5.0
v1.5.1-rc.0
e02da62 1.5.1-rc.0
80c6cf6 release 1.5.0
8cee0e5 1.4.3
765ae07 initial
v1.4.3
v1.5.0
v1.5.1-rc.0
v2.0.0
M package.json
| Command | 1.4.2 becomes |
|---|---|
npm version patch |
1.4.3 |
npm version minor |
1.5.0 |
npm version major |
2.0.0 |
npm version premajor --preid rc |
2.0.0-rc.0 |
npm version prerelease --preid rc |
1.4.3-rc.0, then 1.4.3-rc.1, … |
-m "release %s" sets the commit message (%s is the version). --no-git-tag-version only edits the files, which is what release tools and monorepos use. The preversion / version / postversion lifecycle scripts run around it: tests in preversion, a changelog update in version (added to the same commit), git push --follow-tags in postversion. npm also refuses to run in a dirty working tree, so the release commit contains only the bump.
dist-tags: what "latest" means
A dist-tag is a movable label pointing at one version. npm install pkg (no version) installs whatever latest points to; npm publish moves latest to the new version unless you say otherwise. Pre-releases should go out under another tag so nobody gets them by accident:
mkdir -p lib && cd lib
echo '{ "name": "@learner/lib", "version": "1.0.0", "main": "index.js" }' > package.json
echo 'module.exports = "v1";' > index.js
npm publish > /dev/null 2>&1
npm version 2.0.0-rc.0 --no-git-tag-version > /dev/null
echo 'module.exports = "v2 rc";' > index.js
npm publish 2>&1 | grep -E 'with tag|^npm error' | head -2
npm publish --tag next 2>&1 | grep -E 'with tag|^\+'
npm dist-tag ls @learner/lib
mkdir ../app && cd ../app && npm init -y > /dev/null
npm install @learner/lib > /dev/null 2>&1 && npm ls @learner/lib | tail -2
npm install @learner/lib@next > /dev/null 2>&1 && npm ls @learner/lib | tail -2npm error You must specify a tag using --tag when publishing a prerelease version.
npm error A complete log of this run can be found in: /home/learner/.npm/_logs/2026-10-23T17_42_47_789Z-debug-0.log
npm notice Publishing to http://localhost:4873/ with tag next and default access
+ @learner/lib@2.0.0-rc.0
latest: 1.0.0
next: 2.0.0-rc.0
└── @learner/lib@1.0.0
└── @learner/lib@2.0.0-rc.0
npm 11 refused to publish a pre-release without an explicit tag, which protects latest. With --tag next, users opt in with npm install @learner/lib@next, the usual convention for release candidates (beta, canary and legacy are common too).
Tags are moved and removed with npm dist-tag add / rm. When 2.0.0 ships, or when a bad latest must be rolled back without unpublishing, you move the tag:
mkdir -p lib && cd lib
echo '{ "name": "@learner/lib", "version": "1.0.0" }' > package.json
npm publish > /dev/null 2>&1
npm version 1.1.0 --no-git-tag-version > /dev/null && npm publish > /dev/null 2>&1
npm dist-tag ls @learner/lib
echo "--- 1.1.0 is broken: point latest back at 1.0.0"
npm dist-tag add @learner/lib@1.0.0 latest
npm view @learner/lib dist-tags
npm dist-tag add @learner/lib@1.1.0 broken
npm dist-tag rm @learner/lib broken
npm dist-tag ls @learner/liblatest: 1.1.0
--- 1.1.0 is broken: point latest back at 1.0.0
+latest: @learner/lib@1.0.0
{ latest: '1.0.0' }
+broken: @learner/lib@1.1.0
-broken: @learner/lib@1.1.0
latest: 1.0.0
Moving latest back only affects new installs without a lockfile, or npm install pkg@latest; anyone already locked to 1.1.0 keeps it. That's why you also deprecate it.
npm deprecate
Deprecation attaches a message to one version (or a range). The version stays installable, so no build breaks, but every install prints the warning:
mkdir -p lib && cd lib
echo '{ "name": "@learner/lib", "version": "1.0.0" }' > package.json
npm publish > /dev/null 2>&1
npm version 1.0.1 --no-git-tag-version > /dev/null && npm publish > /dev/null 2>&1
npm deprecate @learner/lib@1.0.0 "contains a parsing bug, upgrade to 1.0.1"
npm view @learner/lib@1.0.0 deprecated
mkdir ../app && cd ../app && npm init -y > /dev/null
npm install @learner/lib@1.0.0 2>&1 | grep deprecated
npm deprecate @learner/lib@1.0.0 ""
npm install @learner/lib@1.0.0 2>&1 | grep -c deprecatednpm notice deprecating @learner/lib@1.0.0 with message "contains a parsing bug, upgrade to 1.0.1"
contains a parsing bug, upgrade to 1.0.1
npm warn deprecated @learner/lib@1.0.0: contains a parsing bug, upgrade to 1.0.1
npm notice undeprecating @learner/lib@1.0.0
0
An empty message un-deprecates. Ranges work too: npm deprecate "@learner/lib@<2" "1.x is no longer maintained" is how a project announces the end of a major line.
| Situation | Tool |
|---|---|
| a release candidate | npm publish --tag next |
| a bad release that people may already have | publish a fix, then npm deprecate pkg@bad "…" |
a bad latest that nobody should get from now on |
npm dist-tag add pkg@good latest + deprecate |
| a leaked secret in a tarball | rotate the secret first; then unpublish if the registry allows it |
| end of life for a major | npm deprecate "pkg@<2" "…" |
Test yourself
What does npm install pkg install when no version is given?
- The highest version number
- The version the
latestdist-tag points to - The newest pre-release
- The first version ever published
How do you publish 2.0.0-rc.0 so that ordinary installs don't pick it up?
- npm publish --private
- npm publish --tag next
- npm version rc
- Pre-releases are never installed
Why deprecate a broken version instead of unpublishing it?
- Unpublish is not a real command
- Deprecation warns users but keeps existing lockfiles and builds working
- Deprecation deletes the tarball
- It's faster