1 ---
2 title: npm-rebuild
3 section: 1
4 description: Rebuild a package
5 github_repo: npm/cli
6 github_branch: release/v10
7 github_path: docs/lib/content/commands/npm-rebuild.md
8 redirect_from:
9 - /cli-documentation/v10/cli-commands/npm-rebuild
10 - /cli-documentation/v10/cli-commands/rebuild
11 - /cli-documentation/v10/commands/npm-rebuild
12 - /cli-documentation/v10/commands/rebuild
13 - /cli-documentation/v10/npm-rebuild
14 - /cli-documentation/v10/rebuild
15 - /cli/v10/cli-commands/npm-rebuild
16 - /cli/v10/cli-commands/rebuild
17 - /cli/v10/commands/rebuild
18 - /cli/v10/npm-rebuild
19 - /cli/v10/rebuild
20 ---
21
22 ### Synopsis
23
24 ```bash
25 npm rebuild [<package-spec>] ...]
26
27 alias: rb
28 ```
29
30 ### Description
31
32 This command does the following:
33
34 1. Execute lifecycle scripts (`preinstall`, `install`, `postinstall`, `prepare`)
35 2. Links bins depending on whether bin links are enabled
36
37 This command is particularly useful in scenarios including but not limited to:
38
39 1. Installing a new version of **node.js**, where you need to recompile all your C++ add-ons with the updated binary.
40 2. Installing with `--ignore-scripts` and `--no-bin-links`, to explicitly choose which packages to build and/or link bins.
41
42 If one or more package specs are provided, then only packages with a name and version matching one of the specifiers will be rebuilt.
43
44 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`).
45
46 If there is a `binding.gyp` file in the root of your package, then npm will use a default install hook:
47
48 ```
49 "scripts": {
50 "install": "node-gyp rebuild"
51 }
52 ```
53
54 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`
55
56 ### Configuration
57
58 #### `global`
59
60 - Default: false
61 - Type: Boolean
62
63 Operates in "global" mode, so that packages are installed into the `prefix` folder instead of the current working directory. See [folders](/cli/v10/configuring-npm/folders) for more on the differences in behavior.
64
65 - packages are installed into the `{prefix}/lib/node_modules` folder, instead of the current working directory.
66 - bin files are linked to `{prefix}/bin`
67 - man pages are linked to `{prefix}/share/man`
68
69 #### `bin-links`
70
71 - Default: true
72 - Type: Boolean
73
74 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
75
76 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.
77
78 #### `foreground-scripts`
79
80 - Default: `false` unless when using `npm pack` or `npm publish` where it defaults to `true`
81 - Type: Boolean
82
83 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.
84
85 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
86
87 #### `ignore-scripts`
88
89 - Default: false
90 - Type: Boolean
91
92 If true, npm does not run scripts specified in package.json files.
93
94 Note that commands explicitly intended to run a particular script, such as `npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run-script` will still run their intended script if `ignore-scripts` is set, but they will _not_ run any pre- or post-scripts.
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 #### `include-workspace-root`
127
128 - Default: false
129 - Type: Boolean
130
131 Include the workspace root when workspaces are enabled for a command.
132
133 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.
134
135 This value is not exported to the environment for child processes.
136
137 #### `install-links`
138
139 - Default: false
140 - Type: Boolean
141
142 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.
143
144 ### See Also
145
146 - [package spec](/cli/v10/using-npm/package-spec)
147 - [npm install](/cli/v10/commands/npm-install)