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