11cb0ef41Sopenharmony_ci---
21cb0ef41Sopenharmony_cititle: npm-rebuild
31cb0ef41Sopenharmony_cisection: 1
41cb0ef41Sopenharmony_cidescription: Rebuild a package
51cb0ef41Sopenharmony_ci---
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci### Synopsis
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci```bash
101cb0ef41Sopenharmony_cinpm rebuild [<package-spec>] ...]
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cialias: rb
131cb0ef41Sopenharmony_ci```
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci### Description
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciThis command does the following:
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci1. Execute lifecycle scripts (`preinstall`, `install`, `postinstall`, `prepare`)
201cb0ef41Sopenharmony_ci2. Links bins depending on whether bin links are enabled
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciThis command is particularly useful in scenarios including but not limited to:
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci1. Installing a new version of **node.js**, where you need to recompile all your C++ add-ons with the updated binary.
251cb0ef41Sopenharmony_ci2. Installing with `--ignore-scripts` and `--no-bin-links`, to explicitly choose which packages to build and/or link bins.
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciIf one or more package specs are provided, then only packages with a name and version matching one of the specifiers will be rebuilt.
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciUsually, 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`).
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciIf there is a `binding.gyp` file in the root of your package, then npm will use a default install hook:
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci```
341cb0ef41Sopenharmony_ci"scripts": {
351cb0ef41Sopenharmony_ci    "install": "node-gyp rebuild"
361cb0ef41Sopenharmony_ci}
371cb0ef41Sopenharmony_ci```
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciThis 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`
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci### Configuration
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci#### `global`
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci* Default: false
461cb0ef41Sopenharmony_ci* Type: Boolean
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciOperates in "global" mode, so that packages are installed into the `prefix`
491cb0ef41Sopenharmony_cifolder instead of the current working directory. See
501cb0ef41Sopenharmony_ci[folders](/configuring-npm/folders) for more on the differences in behavior.
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci* packages are installed into the `{prefix}/lib/node_modules` folder, instead
531cb0ef41Sopenharmony_ci  of the current working directory.
541cb0ef41Sopenharmony_ci* bin files are linked to `{prefix}/bin`
551cb0ef41Sopenharmony_ci* man pages are linked to `{prefix}/share/man`
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci#### `bin-links`
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci* Default: true
621cb0ef41Sopenharmony_ci* Type: Boolean
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ciTells npm to create symlinks (or `.cmd` shims on Windows) for package
651cb0ef41Sopenharmony_ciexecutables.
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ciSet to false to have it not do this. This can be used to work around the
681cb0ef41Sopenharmony_cifact that some file systems don't support symlinks, even on ostensibly Unix
691cb0ef41Sopenharmony_cisystems.
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_ci#### `foreground-scripts`
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci* Default: `false` unless when using `npm pack` or `npm publish` where it
761cb0ef41Sopenharmony_ci  defaults to `true`
771cb0ef41Sopenharmony_ci* Type: Boolean
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ciRun all build scripts (ie, `preinstall`, `install`, and `postinstall`)
801cb0ef41Sopenharmony_ciscripts for installed packages in the foreground process, sharing standard
811cb0ef41Sopenharmony_ciinput, output, and error with the main npm process.
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ciNote that this will generally make installs run slower, and be much noisier,
841cb0ef41Sopenharmony_cibut can be useful for debugging.
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ci#### `ignore-scripts`
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ci* Default: false
911cb0ef41Sopenharmony_ci* Type: Boolean
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ciIf true, npm does not run scripts specified in package.json files.
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_ciNote that commands explicitly intended to run a particular script, such as
961cb0ef41Sopenharmony_ci`npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run-script`
971cb0ef41Sopenharmony_ciwill still run their intended script if `ignore-scripts` is set, but they
981cb0ef41Sopenharmony_ciwill *not* run any pre- or post-scripts.
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_ci#### `workspace`
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci* Default:
1051cb0ef41Sopenharmony_ci* Type: String (can be set multiple times)
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ciEnable running a command in the context of the configured workspaces of the
1081cb0ef41Sopenharmony_cicurrent project while filtering by running only the workspaces defined by
1091cb0ef41Sopenharmony_cithis configuration option.
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_ciValid values for the `workspace` config are either:
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ci* Workspace names
1141cb0ef41Sopenharmony_ci* Path to a workspace directory
1151cb0ef41Sopenharmony_ci* Path to a parent workspace directory (will result in selecting all
1161cb0ef41Sopenharmony_ci  workspaces within that folder)
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ciWhen set for the `npm init` command, this may be set to the folder of a
1191cb0ef41Sopenharmony_ciworkspace which does not yet exist, to create the folder and set it up as a
1201cb0ef41Sopenharmony_cibrand new workspace within the project.
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci#### `workspaces`
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci* Default: null
1271cb0ef41Sopenharmony_ci* Type: null or Boolean
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ciSet to true to run the command in the context of **all** configured
1301cb0ef41Sopenharmony_ciworkspaces.
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_ciExplicitly setting this to false will cause commands like `install` to
1331cb0ef41Sopenharmony_ciignore workspaces altogether. When not set explicitly:
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ci- Commands that operate on the `node_modules` tree (install, update, etc.)
1361cb0ef41Sopenharmony_ciwill link workspaces into the `node_modules` folder. - Commands that do
1371cb0ef41Sopenharmony_ciother things (test, exec, publish, etc.) will operate on the root project,
1381cb0ef41Sopenharmony_ci_unless_ one or more workspaces are specified in the `workspace` config.
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ci#### `include-workspace-root`
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ci* Default: false
1451cb0ef41Sopenharmony_ci* Type: Boolean
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ciInclude the workspace root when workspaces are enabled for a command.
1481cb0ef41Sopenharmony_ci
1491cb0ef41Sopenharmony_ciWhen false, specifying individual workspaces via the `workspace` config, or
1501cb0ef41Sopenharmony_ciall workspaces via the `workspaces` flag, will cause npm to operate only on
1511cb0ef41Sopenharmony_cithe specified workspaces, and not on the root project.
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci#### `install-links`
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ci* Default: false
1581cb0ef41Sopenharmony_ci* Type: Boolean
1591cb0ef41Sopenharmony_ci
1601cb0ef41Sopenharmony_ciWhen set file: protocol dependencies will be packed and installed as regular
1611cb0ef41Sopenharmony_cidependencies instead of creating a symlink. This option has no effect on
1621cb0ef41Sopenharmony_ciworkspaces.
1631cb0ef41Sopenharmony_ci
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ci### See Also
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_ci* [package spec](/using-npm/package-spec)
1691cb0ef41Sopenharmony_ci* [npm install](/commands/npm-install)
170