1 ---
2 title: npm-version
3 section: 1
4 description: Bump a package version
5 github_repo: npm/cli
6 github_branch: latest
7 github_path: docs/lib/content/commands/npm-version.md
8 redirect_from:
9 - /cli-commands/npm-version
10 - /cli-commands/version
11 - /cli-documentation/cli-commands/npm-version
12 - /cli-documentation/cli-commands/version
13 - /cli-documentation/commands/npm-version
14 - /cli-documentation/commands/version
15 - /cli-documentation/npm-version
16 - /cli-documentation/v11/cli-commands/npm-version
17 - /cli-documentation/v11/cli-commands/version
18 - /cli-documentation/v11/commands/npm-version
19 - /cli-documentation/v11/commands/version
20 - /cli-documentation/v11/npm-version
21 - /cli-documentation/v11/version
22 - /cli-documentation/version
23 - /cli/cli-commands/npm-version
24 - /cli/cli-commands/version
25 - /cli/commands/npm-version
26 - /cli/commands/version
27 - /cli/npm-version
28 - /cli/v11/cli-commands/npm-version
29 - /cli/v11/cli-commands/version
30 - /cli/v11/commands/version
31 - /cli/v11/npm-version
32 - /cli/v11/version
33 - /cli/version
34 - /commands/npm-version
35 - /commands/version
36 ---
37
38 ### Synopsis
39
40 ```bash
41 npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]
42
43 alias: verison
44 ```
45
46 ### Configuration
47
48 #### `allow-same-version`
49
50 - Default: false
51 - Type: Boolean
52
53 Prevents throwing an error when `npm version` is used to set the new version to the same value as the current version.
54
55 #### `commit-hooks`
56
57 - Default: true
58 - Type: Boolean
59
60 Run git commit hooks when using the `npm version` command.
61
62 #### `git-tag-version`
63
64 - Default: true
65 - Type: Boolean
66
67 Tag the commit when using the `npm version` command. Setting this to false results in no commit being made at all.
68
69 #### `json`
70
71 - Default: false
72 - Type: Boolean
73
74 Whether or not to output JSON data, rather than the normal output.
75
76 - In `npm pkg set` it enables parsing set values with JSON.parse() before saving them to your `package.json`.
77
78 Not supported by all npm commands.
79
80 #### `preid`
81
82 - Default: ""
83 - Type: String
84
85 The "prerelease identifier" to use as a prefix for the "prerelease" part of a semver. Like the `rc` in `1.2.0-rc.8`.
86
87 #### `sign-git-tag`
88
89 - Default: false
90 - Type: Boolean
91
92 If set to true, then the `npm version` command will tag the version using `-s` to add a signature.
93
94 Note that git requires you to have set up GPG keys in your git configs for this to work properly.
95
96 #### `save`
97
98 - Default: `true` unless when using `npm update` where it defaults to `false`
99 - Type: Boolean
100
101 Save installed packages to a `package.json` file as dependencies.
102
103 When used with the `npm rm` command, removes the dependency from `package.json`.
104
105 Will also prevent writing to `package-lock.json` if set to `false`.
106
107 #### `workspace`
108
109 - Default:
110 - Type: String (can be set multiple times)
111
112 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.
113
114 Valid values for the `workspace` config are either:
115
116 - Workspace names
117 - Path to a workspace directory
118 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
119
120 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.
121
122 This value is not exported to the environment for child processes.
123
124 #### `workspaces`
125
126 - Default: null
127 - Type: null or Boolean
128
129 Set to true to run the command in the context of **all** configured workspaces.
130
131 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
132
133 - Commands that operate on the `node_modules` tree (install, update, etc.) will link workspaces into the `node_modules` folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, _unless_ one or more workspaces are specified in the `workspace` config.
134
135 This value is not exported to the environment for child processes.
136
137 #### `workspaces-update`
138
139 - Default: true
140 - Type: Boolean
141
142 If set to true, the npm cli will run an update after operations that may possibly change the workspaces installed to the `node_modules` folder.
143
144 #### `include-workspace-root`
145
146 - Default: false
147 - Type: Boolean
148
149 Include the workspace root when workspaces are enabled for a command.
150
151 When false, specifying individual workspaces via the `workspace` config, or all workspaces via the `workspaces` flag, will cause npm to operate only on the specified workspaces, and not on the root project.
152
153 This value is not exported to the environment for child processes.
154
155 #### `ignore-scripts`
156
157 - Default: false
158 - Type: Boolean
159
160 If true, npm does not run scripts specified in package.json files.
161
162 Note that commands explicitly intended to run a particular script, such as `npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run` will still run their intended script if `ignore-scripts` is set, but they will _not_ run any pre- or post-scripts.
163
164 ### Description
165
166 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`.
167
168 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.
169
170 **Note:** If the current version is a prerelease version, `patch` will simply remove the prerelease suffix without incrementing the patch version number. For example, `1.2.0-5` becomes `1.2.0` with `npm version patch`, not `1.2.1`.
171
172 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.
173
174 **Note:** Git integration requires a reasonably recent version of git (2.0.0 or later is recommended). If you encounter issues with git commands, ensure your git installation is up to date.
175
176 If supplied with `-m` or [`--message` config](/cli/v11/using-npm/config#message) 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:
177
178 ```bash
179 npm version patch -m "Upgrade to %s for reasons"
180 ```
181
182 If the [`sign-git-tag` config](/cli/v11/using-npm/config#sign-git-tag) 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:
183
184 ```bash
185 $ npm config set sign-git-tag true
186 $ npm version patch
187
188 You need a passphrase to unlock the secret key for user: "isaacs (http://blog.izs.me/) <i@izs.me>"
189 2048-bit RSA key, ID 6C481CF6, created 2010-08-31
190
191 Enter passphrase:
192 ```
193
194 If `preversion`, `version`, or `postversion` are in the `scripts` property of the package.json, they will be executed as part of running `npm version`.
195
196 The exact order of execution is as follows:
197
198 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.
199 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`.
200 3. Bump `version` in `package.json` as requested (`patch`, `minor`, `major`, etc).
201 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`.
202 5. Commit and tag.
203 6. Run the `postversion` script. Use it to clean up the file system or automatically push the commit and/or tag.
204
205 Take the following example:
206
207 ```json
208 {
209 "scripts": {
210 "preversion": "npm test",
211 "version": "npm run build && git add -A dist",
212 "postversion": "git push && git push --tags && rm -rf build/temp"
213 }
214 }
215 ```
216
217 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.
218
219 ### See Also
220
221 - [npm init](/cli/v11/commands/npm-init)
222 - [npm run](/cli/v11/commands/npm-run)
223 - [npm scripts](/cli/v11/using-npm/scripts)
224 - [package.json](/cli/v11/configuring-npm/package-json)
225 - [config](/cli/v11/using-npm/config)