update package.json version automatically
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If you want to update the version in package.json automatically, the safest default is npm version. It understands semantic versioning, updates the related npm metadata files, and can also create the release commit and tag for you. That is better than editing JSON manually because it keeps the version bump tied to the package manager's own workflow.
Use npm version for normal release bumps
For patch, minor, major, and prerelease increments, npm version is the standard tool.
You can also set an explicit version:
And if you want a prerelease:
In current npm documentation, npm version updates package.json, package-lock.json, and npm-shrinkwrap.json when applicable. In a Git repository, it also creates the version commit and tag by default.
Control whether Git commit and tag are created
Sometimes you want npm to update the version files but let CI or release tooling handle commits and tags later. In that case, disable the Git side effects.
That is useful in automated pipelines where another step is responsible for composing the final release commit. It also helps when you want to inspect generated artifacts before tagging anything.
If you do skip the built-in Git behavior, make the follow-up steps explicit:
The key point is consistency. Either let npm own the release commit and tag, or disable that behavior and own it fully in your pipeline.
Use lifecycle scripts around the version bump
One of the most practical features of npm version is that it runs lifecycle scripts. That lets you enforce tests before the bump, generate files during the bump, and push tags afterward.
This is a solid pattern because it turns versioning into a repeatable release step rather than a manual edit followed by a pile of human memory.
CI workflows usually separate bumping from publishing
In CI, many teams run the bump with --no-git-tag-version, inspect the resulting version, build artifacts, and publish only if the pipeline passes. That keeps failed builds from creating misleading tags.
You can also use from-git when Git tags are already your source of truth:
That approach works well when release orchestration happens outside npm and the repository tags define the version.
Avoid manual JSON editing unless you really need it
You can technically edit package.json directly, or use generic JSON tools, but that is usually the wrong default for release automation. Direct editing does not automatically follow npm's version rules and can leave the surrounding workflow inconsistent.
The more your release process depends on predictable tags, lockfile updates, and script hooks, the more valuable npm version becomes.
Common Pitfalls
The most common mistake is bumping the version in a dirty working tree. npm can refuse the operation or capture unrelated changes in the release commit.
Another issue is assuming --no-git-tag-version means "skip only the tag." Current npm docs describe that flag as disabling the version commit and tag behavior, so do not assume a commit will still appear.
Teams also forget that prerelease bumps follow semver rules. If you use prerelease versions, decide whether the next step should be another prerelease or a final release.
Finally, do not forget the lockfile. One reason to prefer npm version is that it updates the version metadata consistently across npm-managed files.
Summary
- Use
npm versionas the default way to bumppackage.jsonautomatically. - It handles semantic version increments and updates npm-managed version files.
- By default it also creates a Git version commit and tag in a repository.
- Use
--no-git-tag-versionwhen CI should control commit and tag creation itself. - Add
preversion,version, andpostversionscripts to make the release flow repeatable.

