1--- 2section: cli-commands 3title: npm-version 4description: Bump a package version 5--- 6 7# npm-version(1) 8 9## Bump a package version 10 11### Synopsis 12 13```bash 14npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git] 15 16'npm [-v | --version]' to print npm version 17'npm view <pkg> version' to view a package's published version 18'npm ls' to inspect current package/dependency versions 19``` 20 21### Description 22 23Run this in a package directory to bump the version and write the new 24data back to `package.json`, `package-lock.json`, and, if present, `npm-shrinkwrap.json`. 25 26The `newversion` argument should be a valid semver string, a 27valid second argument to [semver.inc](https://github.com/npm/node-semver#functions) (one of `patch`, `minor`, `major`, 28`prepatch`, `preminor`, `premajor`, `prerelease`), or `from-git`. In the second case, 29the existing version will be incremented by 1 in the specified field. 30`from-git` will try to read the latest git tag, and use that as the new npm version. 31 32If run in a git repo, it will also create a version commit and tag. 33This behavior is controlled by `git-tag-version` (see below), and can 34be disabled on the command line by running `npm --no-git-tag-version version`. 35It will fail if the working directory is not clean, unless the `-f` or 36`--force` flag is set. 37 38If supplied with `-m` or `--message` config option, npm will 39use it as a commit message when creating a version commit. If the 40`message` config contains `%s` then that will be replaced with the 41resulting version number. For example: 42 43```bash 44npm version patch -m "Upgrade to %s for reasons" 45``` 46 47If the `sign-git-tag` config is set, then the tag will be signed using 48the `-s` flag to git. Note that you must have a default GPG key set up 49in your git config for this to work properly. For example: 50 51```bash 52$ npm config set sign-git-tag true 53$ npm version patch 54 55You need a passphrase to unlock the secret key for 56user: "isaacs (http://blog.izs.me/) <i@izs.me>" 572048-bit RSA key, ID 6C481CF6, created 2010-08-31 58 59Enter passphrase: 60``` 61 62If `preversion`, `version`, or `postversion` are in the `scripts` property of 63the package.json, they will be executed as part of running `npm version`. 64 65The exact order of execution is as follows: 66 1. Check to make sure the git working directory is clean before we get started. 67 Your scripts may add files to the commit in future steps. 68 This step is skipped if the `--force` flag is set. 69 2. Run the `preversion` script. These scripts have access to the old `version` in package.json. 70 A typical use would be running your full test suite before deploying. 71 Any files you want added to the commit should be explicitly added using `git add`. 72 3. Bump `version` in `package.json` as requested (`patch`, `minor`, `major`, etc). 73 4. Run the `version` script. These scripts have access to the new `version` in package.json 74 (so they can incorporate it into file headers in generated files for example). 75 Again, scripts should explicitly add generated files to the commit using `git add`. 76 5. Commit and tag. 77 6. Run the `postversion` script. Use it to clean up the file system or automatically push 78 the commit and/or tag. 79 80Take the following example: 81 82```json 83 "scripts": { 84 "preversion": "npm test", 85 "version": "npm run build && git add -A dist", 86 "postversion": "git push && git push --tags && rm -rf build/temp" 87 } 88``` 89 90This runs all your tests, and proceeds only if they pass. Then runs your `build` script, and 91adds everything in the `dist` directory to the commit. After the commit, it pushes the new commit 92and tag up to the server, and deletes the `build/temp` directory. 93 94### Configuration 95 96#### allow-same-version 97 98* Default: false 99* Type: Boolean 100 101Prevents throwing an error when `npm version` is used to set the new version 102to the same value as the current version. 103 104#### git-tag-version 105 106* Default: true 107* Type: Boolean 108 109Commit and tag the version change. 110 111#### commit-hooks 112 113* Default: true 114* Type: Boolean 115 116Run git commit hooks when committing the version change. 117 118#### sign-git-tag 119 120* Default: false 121* Type: Boolean 122 123Pass the `-s` flag to git to sign the tag. 124 125Note that you must have a default GPG key set up in your git config for this to work properly. 126 127### See Also 128 129* [npm init](/cli-commands/npm-init) 130* [npm run-script](/cli-commands/npm-run-script) 131* [npm scripts](/using-npm/scripts) 132* [package.json](/configuring-npm/package-json) 133* [semver](/using-npm/semver) 134* [config](/using-npm/config) 135