1 ---
2 title: npm-version
3 section: 1
4 description: Bump a package version
5 github_repo: npm/cli
6 github_branch: release/v7
7 github_path: docs/content/commands/npm-version.md
8 redirect_from:
9 - /cli-documentation/v7/cli-commands/npm-version
10 - /cli-documentation/v7/cli-commands/version
11 - /cli-documentation/v7/commands/npm-version
12 - /cli-documentation/v7/commands/version
13 - /cli-documentation/v7/npm-version
14 - /cli-documentation/v7/version
15 - /cli/v7/cli-commands/npm-version
16 - /cli/v7/cli-commands/version
17 - /cli/v7/commands/version
18 - /cli/v7/npm-version
19 - /cli/v7/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 ### Configuration
33
34 #### `allow-same-version`
35
36 - Default: false
37 - Type: Boolean
38
39 Prevents throwing an error when `npm version` is used to set the new version to the same value as the current version.
40
41 #### `commit-hooks`
42
43 - Default: true
44 - Type: Boolean
45
46 Run git commit hooks when using the `npm version` command.
47
48 #### `git-tag-version`
49
50 - Default: true
51 - Type: Boolean
52
53 Tag the commit when using the `npm version` command.
54
55 #### `json`
56
57 - Default: false
58 - Type: Boolean
59
60 Whether or not to output JSON data, rather than the normal output.
61
62 - In `npm pkg set` it enables parsing set values with JSON.parse() before saving them to your `package.json`.
63
64 Not supported by all npm commands.
65
66 #### `preid`
67
68 - Default: ""
69 - Type: String
70
71 The "prerelease identifier" to use as a prefix for the "prerelease" part of a semver. Like the `rc` in `1.2.0-rc.8`.
72
73 #### `sign-git-tag`
74
75 - Default: false
76 - Type: Boolean
77
78 If set to true, then the `npm version` command will tag the version using `-s` to add a signature.
79
80 Note that git requires you to have set up GPG keys in your git configs for this to work properly.
81
82 #### `workspace`
83
84 - Default:
85 - Type: String (can be set multiple times)
86
87 Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
88
89 Valid values for the `workspace` config are either:
90
91 - Workspace names
92 - Path to a workspace directory
93 - Path to a parent workspace directory (will result to selecting all of the nested workspaces)
94
95 When set for the `npm init` command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
96
97 This value is not exported to the environment for child processes.
98
99 #### `workspaces`
100
101 - Default: false
102 - Type: Boolean
103
104 Enable running a command in the context of **all** the configured workspaces.
105
106 This value is not exported to the environment for child processes.
107
108 ### Description
109
110 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`.
111
112 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.
113
114 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.
115
116 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:
117
118 ```bash
119 npm version patch -m "Upgrade to %s for reasons"
120 ```
121
122 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:
123
124 ```bash
125 $ npm config set sign-git-tag true
126 $ npm version patch
127
128 You need a passphrase to unlock the secret key for
129 user: "isaacs (http://blog.izs.me/) <i@izs.me>"
130 2048-bit RSA key, ID 6C481CF6, created 2010-08-31
131
132 Enter passphrase:
133 ```
134
135 If `preversion`, `version`, or `postversion` are in the `scripts` property of the package.json, they will be executed as part of running `npm version`.
136
137 The exact order of execution is as follows:
138
139 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.
140 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`.
141 3. Bump `version` in `package.json` as requested (`patch`, `minor`, `major`, etc).
142 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`.
143 5. Commit and tag.
144 6. Run the `postversion` script. Use it to clean up the file system or automatically push the commit and/or tag.
145
146 Take the following example:
147
148 ```json
149 {
150 "scripts": {
151 "preversion": "npm test",
152 "version": "npm run build && git add -A dist",
153 "postversion": "git push && git push --tags && rm -rf build/temp"
154 }
155 }
156 ```
157
158 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.
159
160 ### See Also
161
162 - [npm init](/cli/v7/commands/npm-init)
163 - [npm run-script](/cli/v7/commands/npm-run-script)
164 - [npm scripts](/cli/v7/using-npm/scripts)
165 - [package.json](/cli/v7/configuring-npm/package-json)
166 - [config](/cli/v7/using-npm/config)