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 #### `workspace`
97
98 - Default:
99 - Type: String (can be set multiple times)
100
101 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.
102
103 Valid values for the `workspace` config are either:
104
105 - Workspace names
106 - Path to a workspace directory
107 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
108
109 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.
110
111 This value is not exported to the environment for child processes.
112
113 #### `workspaces`
114
115 - Default: null
116 - Type: null or Boolean
117
118 Set to true to run the command in the context of **all** configured workspaces.
119
120 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
121
122 - 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.
123
124 This value is not exported to the environment for child processes.
125
126 #### `workspaces-update`
127
128 - Default: true
129 - Type: Boolean
130
131 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.
132
133 #### `include-workspace-root`
134
135 - Default: false
136 - Type: Boolean
137
138 Include the workspace root when workspaces are enabled for a command.
139
140 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.
141
142 This value is not exported to the environment for child processes.
143
144 ### Description
145
146 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`.
147
148 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.
149
150 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.
151
152 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:
153
154 ```bash
155 npm version patch -m "Upgrade to %s for reasons"
156 ```
157
158 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:
159
160 ```bash
161 $ npm config set sign-git-tag true
162 $ npm version patch
163
164 You need a passphrase to unlock the secret key for
165 user: "isaacs (http://blog.izs.me/) <i@izs.me>"
166 2048-bit RSA key, ID 6C481CF6, created 2010-08-31
167
168 Enter passphrase:
169 ```
170
171 If `preversion`, `version`, or `postversion` are in the `scripts` property of the package.json, they will be executed as part of running `npm version`.
172
173 The exact order of execution is as follows:
174
175 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.
176 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`.
177 3. Bump `version` in `package.json` as requested (`patch`, `minor`, `major`, etc).
178 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`.
179 5. Commit and tag.
180 6. Run the `postversion` script. Use it to clean up the file system or automatically push the commit and/or tag.
181
182 Take the following example:
183
184 ```json
185 {
186 "scripts": {
187 "preversion": "npm test",
188 "version": "npm run build && git add -A dist",
189 "postversion": "git push && git push --tags && rm -rf build/temp"
190 }
191 }
192 ```
193
194 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.
195
196 ### See Also
197
198 - [npm init](/cli/v11/commands/npm-init)
199 - [npm run-script](/cli/v11/commands/npm-run-script)
200 - [npm scripts](/cli/v11/using-npm/scripts)
201 - [package.json](/cli/v11/configuring-npm/package-json)
202 - [config](/cli/v11/using-npm/config)