codekingpro/portable-devtools
114k
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.
40It is also suppressed if the package specifies `"gypfile": false`
41
42### Configuration
43
44#### `global`
45
46* Default: false
47* Type: Boolean
48
49Operates in "global" mode, so that packages are installed into the `prefix`
50folder instead of the current working directory. See
51[folders](/configuring-npm/folders) for more on the differences in behavior.
52
53* packages are installed into the `{prefix}/lib/node_modules` folder, instead
54 of the current working directory.
55* bin files are linked to `{prefix}/bin`
56* man pages are linked to `{prefix}/share/man`
57
58
59
60#### `bin-links`
61
62* Default: true
63* Type: Boolean
64
65Tells npm to create symlinks (or `.cmd` shims on Windows) for package
66executables.
67
68Set to false to have it not do this. This can be used to work around the
69fact that some file systems don't support symlinks, even on ostensibly Unix
70systems.
71
72
73
74#### `foreground-scripts`
75
76* Default: `false` unless when using `npm pack` or `npm publish` where it
77 defaults to `true`
78* Type: Boolean
79
80Run all build scripts (ie, `preinstall`, `install`, and `postinstall`)
81scripts for installed packages in the foreground process, sharing standard
82input, output, and error with the main npm process.
83
84Note that this will generally make installs run slower, and be much noisier,
85but can be useful for debugging.
86
87
88
89#### `ignore-scripts`
90
91* Default: false
92* Type: Boolean
93
94If true, npm does not run scripts specified in package.json files.
95
96Note that commands explicitly intended to run a particular script, such as
97`npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run` will still
98run their intended script if `ignore-scripts` is set, but they will *not*
99run any pre- or post-scripts.
100
101
102
103#### `workspace`
104
105* Default:
106* Type: String (can be set multiple times)
107
108Enable running a command in the context of the configured workspaces of the
109current project while filtering by running only the workspaces defined by
110this configuration option.
111
112Valid values for the `workspace` config are either:
113
114* Workspace names
115* Path to a workspace directory
116* Path to a parent workspace directory (will result in selecting all
117 workspaces within that folder)
118
119When set for the `npm init` command, this may be set to the folder of a
120workspace which does not yet exist, to create the folder and set it up as a
121brand new workspace within the project.
122
123This value is not exported to the environment for child processes.
124
125#### `workspaces`
126
127* Default: null
128* Type: null or Boolean
129
130Set to true to run the command in the context of **all** configured
131workspaces.
132
133Explicitly setting this to false will cause commands like `install` to
134ignore workspaces altogether. When not set explicitly:
135
136- Commands that operate on the `node_modules` tree (install, update, etc.)
137will link workspaces into the `node_modules` folder. - Commands that do
138other things (test, exec, publish, etc.) will operate on the root project,
139_unless_ one or more workspaces are specified in the `workspace` config.
140
141This value is not exported to the environment for child processes.
142
143#### `include-workspace-root`
144
145* Default: false
146* Type: Boolean
147
148Include the workspace root when workspaces are enabled for a command.
149
150When false, specifying individual workspaces via the `workspace` config, or
151all workspaces via the `workspaces` flag, will cause npm to operate only on
152the specified workspaces, and not on the root project.
153
154This value is not exported to the environment for child processes.
155
156#### `install-links`
157
158* Default: false
159* Type: Boolean
160
161When set file: protocol dependencies will be packed and installed as regular
162dependencies instead of creating a symlink. This option has no effect on
163workspaces.
164
165
166
167### See Also
168
169* [package spec](/using-npm/package-spec)
170* [npm install](/commands/npm-install)
171 