1 ---
2 title: npm-rebuild
3 section: 1
4 description: Rebuild a package
5 github_repo: npm/cli
6 github_branch: latest
7 github_path: docs/lib/content/commands/npm-rebuild.md
8 redirect_from:
9 - /cli-commands/npm-rebuild
10 - /cli-commands/rebuild
11 - /cli-documentation/cli-commands/npm-rebuild
12 - /cli-documentation/cli-commands/rebuild
13 - /cli-documentation/commands/npm-rebuild
14 - /cli-documentation/commands/rebuild
15 - /cli-documentation/npm-rebuild
16 - /cli-documentation/rebuild
17 - /cli-documentation/v11/cli-commands/npm-rebuild
18 - /cli-documentation/v11/cli-commands/rebuild
19 - /cli-documentation/v11/commands/npm-rebuild
20 - /cli-documentation/v11/commands/rebuild
21 - /cli-documentation/v11/npm-rebuild
22 - /cli-documentation/v11/rebuild
23 - /cli/cli-commands/npm-rebuild
24 - /cli/cli-commands/rebuild
25 - /cli/commands/npm-rebuild
26 - /cli/commands/rebuild
27 - /cli/npm-rebuild
28 - /cli/rebuild
29 - /cli/v11/cli-commands/npm-rebuild
30 - /cli/v11/cli-commands/rebuild
31 - /cli/v11/commands/rebuild
32 - /cli/v11/npm-rebuild
33 - /cli/v11/rebuild
34 - /commands/npm-rebuild
35 - /commands/rebuild
36 ---
37
38 ### Synopsis
39
40 ```bash
41 npm rebuild [<package-spec>] ...]
42
43 alias: rb
44 ```
45
46 ### Description
47
48 This command does the following:
49
50 1. Execute lifecycle scripts (`preinstall`, `install`, `postinstall`, `prepare`)
51 2. Links bins depending on whether bin links are enabled
52
53 This command is particularly useful in scenarios including but not limited to:
54
55 1. Installing a new version of **node.js**, where you need to recompile all your C++ add-ons with the updated binary.
56 2. Installing with `--ignore-scripts` and `--no-bin-links`, to explicitly choose which packages to build and/or link bins.
57
58 If one or more package specs are provided, then only packages with a name and version matching one of the specifiers will be rebuilt.
59
60 Usually, you should not need to run `npm rebuild` as it is already done for you as part of npm install (unless you suppressed these steps with `--ignore-scripts` or `--no-bin-links`).
61
62 If there is a `binding.gyp` file in the root of your package, then npm will use a default install hook:
63
64 ```
65 "scripts": {
66 "install": "node-gyp rebuild"
67 }
68 ```
69
70 This default behavior is suppressed if the `package.json` has its own `install` or `preinstall` scripts. It is also suppressed if the package specifies `"gypfile": false`
71
72 ### Configuration
73
74 #### `global`
75
76 - Default: false
77 - Type: Boolean
78
79 Operates in "global" mode, so that packages are installed into the `prefix` folder instead of the current working directory. See [folders](/cli/v11/configuring-npm/folders) for more on the differences in behavior.
80
81 - packages are installed into the `{prefix}/lib/node_modules` folder, instead of the current working directory.
82 - bin files are linked to `{prefix}/bin`
83 - man pages are linked to `{prefix}/share/man`
84
85 #### `bin-links`
86
87 - Default: true
88 - Type: Boolean
89
90 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
91
92 Set to false to have it not do this. This can be used to work around the fact that some file systems don't support symlinks, even on ostensibly Unix systems.
93
94 #### `foreground-scripts`
95
96 - Default: `false` unless when using `npm pack` or `npm publish` where it defaults to `true`
97 - Type: Boolean
98
99 Run all build scripts (ie, `preinstall`, `install`, and `postinstall`) scripts for installed packages in the foreground process, sharing standard input, output, and error with the main npm process.
100
101 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
102
103 #### `ignore-scripts`
104
105 - Default: false
106 - Type: Boolean
107
108 If true, npm does not run scripts specified in package.json files.
109
110 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.
111
112 #### `allow-scripts`
113
114 - Default: ""
115 - Type: String (can be set multiple times)
116
117 Comma-separated list of packages whose install-time lifecycle scripts (`preinstall`, `install`, `postinstall`, and `prepare` for non-registry dependencies) are allowed to run.
118
119 This setting is intended for one-off and global contexts: `npm exec`, `npx`, and `npm install -g`, where no project `package.json` is involved. For team-wide policy in a project, use the `allowScripts` field in `package.json` (which also supports explicit denials), or configure it in `.npmrc`. Passing `--allow-scripts` on the command line during a project-scoped `npm install`, `ci`, `update`, or `rebuild` is an error.
120
121 Each name is matched against a dependency's resolved identity, not against the package's self-reported name. `--ignore-scripts` and `--dangerously-allow-all-scripts` both override this setting.
122
123 #### `strict-allow-scripts`
124
125 - Default: false
126 - Type: Boolean
127
128 If `true`, turn the install-script policy from a warning into a hard error: any dependency with install scripts not covered by `allowScripts` will fail the install instead of running with a notice.
129
130 Dependencies explicitly denied with `false` in `allowScripts` are always silently skipped; this setting only affects unreviewed entries. `--ignore-scripts` and `--dangerously-allow-all-scripts` both override this setting.
131
132 #### `dangerously-allow-all-scripts`
133
134 - Default: false
135 - Type: Boolean
136
137 If `true`, bypass the `allowScripts` policy entirely and run every dependency install script regardless of whether it was approved or denied. Intended as a migration escape hatch only; its use is strongly discouraged. `--ignore-scripts` still takes precedence over this setting.
138
139 #### `workspace`
140
141 - Default:
142 - Type: String (can be set multiple times)
143
144 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.
145
146 Valid values for the `workspace` config are either:
147
148 - Workspace names
149 - Path to a workspace directory
150 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
151
152 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.
153
154 This value is not exported to the environment for child processes.
155
156 #### `workspaces`
157
158 - Default: null
159 - Type: null or Boolean
160
161 Set to true to run the command in the context of **all** configured workspaces.
162
163 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
164
165 - 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.
166
167 This value is not exported to the environment for child processes.
168
169 #### `include-workspace-root`
170
171 - Default: false
172 - Type: Boolean
173
174 Include the workspace root when workspaces are enabled for a command.
175
176 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.
177
178 This value is not exported to the environment for child processes.
179
180 #### `install-links`
181
182 - Default: false
183 - Type: Boolean
184
185 When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
186
187 ### See Also
188
189 - [package spec](/cli/v11/using-npm/package-spec)
190 - [npm install](/cli/v11/commands/npm-install)