1---
2title: npm-rebuild
3section: 1
4description: Rebuild a package
5---
6
7### Synopsis
8
9```bash
10npm rebuild [<package-spec>] ...]
11
12alias: rb
13```
14
15### Description
16
17This command does the following:
18
191. Execute lifecycle scripts (`preinstall`, `install`, `postinstall`, `prepare`)
202. Links bins depending on whether bin links are enabled
21
22This command is particularly useful in scenarios including but not limited to:
23
241. Installing a new version of **node.js**, where you need to recompile all your C++ add-ons with the updated binary.
252. Installing with `--ignore-scripts` and `--no-bin-links`, to explicitly choose which packages to build and/or link bins.
26
27If one or more package specs are provided, then only packages with a name and version matching one of the specifiers will be rebuilt.
28
29Usually, 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`).
30
31If there is a `binding.gyp` file in the root of your package, then npm will use a default install hook:
32
33```
34"scripts": {
35    "install": "node-gyp rebuild"
36}
37```
38
39This 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`
40
41### Configuration
42
43#### `global`
44
45* Default: false
46* Type: Boolean
47
48Operates in "global" mode, so that packages are installed into the `prefix`
49folder instead of the current working directory. See
50[folders](/configuring-npm/folders) for more on the differences in behavior.
51
52* packages are installed into the `{prefix}/lib/node_modules` folder, instead
53  of the current working directory.
54* bin files are linked to `{prefix}/bin`
55* man pages are linked to `{prefix}/share/man`
56
57
58
59#### `bin-links`
60
61* Default: true
62* Type: Boolean
63
64Tells npm to create symlinks (or `.cmd` shims on Windows) for package
65executables.
66
67Set to false to have it not do this. This can be used to work around the
68fact that some file systems don't support symlinks, even on ostensibly Unix
69systems.
70
71
72
73#### `foreground-scripts`
74
75* Default: `false` unless when using `npm pack` or `npm publish` where it
76  defaults to `true`
77* Type: Boolean
78
79Run all build scripts (ie, `preinstall`, `install`, and `postinstall`)
80scripts for installed packages in the foreground process, sharing standard
81input, output, and error with the main npm process.
82
83Note that this will generally make installs run slower, and be much noisier,
84but can be useful for debugging.
85
86
87
88#### `ignore-scripts`
89
90* Default: false
91* Type: Boolean
92
93If true, npm does not run scripts specified in package.json files.
94
95Note that commands explicitly intended to run a particular script, such as
96`npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run-script`
97will still run their intended script if `ignore-scripts` is set, but they
98will *not* run any pre- or post-scripts.
99
100
101
102#### `workspace`
103
104* Default:
105* Type: String (can be set multiple times)
106
107Enable running a command in the context of the configured workspaces of the
108current project while filtering by running only the workspaces defined by
109this configuration option.
110
111Valid values for the `workspace` config are either:
112
113* Workspace names
114* Path to a workspace directory
115* Path to a parent workspace directory (will result in selecting all
116  workspaces within that folder)
117
118When set for the `npm init` command, this may be set to the folder of a
119workspace which does not yet exist, to create the folder and set it up as a
120brand new workspace within the project.
121
122This value is not exported to the environment for child processes.
123
124#### `workspaces`
125
126* Default: null
127* Type: null or Boolean
128
129Set to true to run the command in the context of **all** configured
130workspaces.
131
132Explicitly setting this to false will cause commands like `install` to
133ignore workspaces altogether. When not set explicitly:
134
135- Commands that operate on the `node_modules` tree (install, update, etc.)
136will link workspaces into the `node_modules` folder. - Commands that do
137other things (test, exec, publish, etc.) will operate on the root project,
138_unless_ one or more workspaces are specified in the `workspace` config.
139
140This value is not exported to the environment for child processes.
141
142#### `include-workspace-root`
143
144* Default: false
145* Type: Boolean
146
147Include the workspace root when workspaces are enabled for a command.
148
149When false, specifying individual workspaces via the `workspace` config, or
150all workspaces via the `workspaces` flag, will cause npm to operate only on
151the specified workspaces, and not on the root project.
152
153This value is not exported to the environment for child processes.
154
155#### `install-links`
156
157* Default: false
158* Type: Boolean
159
160When set file: protocol dependencies will be packed and installed as regular
161dependencies instead of creating a symlink. This option has no effect on
162workspaces.
163
164
165
166### See Also
167
168* [package spec](/using-npm/package-spec)
169* [npm install](/commands/npm-install)
170