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