1 ---
2 title: npm-ci
3 section: 1
4 description: Clean install a project
5 github_repo: npm/cli
6 github_branch: release/v8
7 github_path: docs/lib/content/commands/npm-ci.md
8 redirect_from:
9 - /cli-documentation/v8/ci
10 - /cli-documentation/v8/cli-commands/ci
11 - /cli-documentation/v8/cli-commands/npm-ci
12 - /cli-documentation/v8/commands/ci
13 - /cli-documentation/v8/commands/npm-ci
14 - /cli-documentation/v8/npm-ci
15 - /cli/v8/ci
16 - /cli/v8/cli-commands/ci
17 - /cli/v8/cli-commands/npm-ci
18 - /cli/v8/commands/ci
19 - /cli/v8/npm-ci
20 ---
21
22 ### Synopsis
23
24 ```bash
25 npm ci
26
27 aliases: clean-install, ic, install-clean, isntall-clean
28 ```
29
30 ### Description
31
32 This command is similar to [`npm install`](/cli/v8/commands/npm-install), except it's meant to be used in automated environments such as test platforms, continuous integration, and deployment -- or any situation where you want to make sure you're doing a clean install of your dependencies.
33
34 The main differences between using `npm install` and `npm ci` are:
35
36 - The project **must** have an existing `package-lock.json` or `npm-shrinkwrap.json`.
37 - If dependencies in the package lock do not match those in `package.json`, `npm ci` will exit with an error, instead of updating the package lock.
38 - `npm ci` can only install entire projects at a time: individual dependencies cannot be added with this command.
39 - If a `node_modules` is already present, it will be automatically removed before `npm ci` begins its install.
40 - It will never write to `package.json` or any of the package-locks: installs are essentially frozen.
41
42 NOTE: If you create your `package-lock.json` file by running `npm install` with flags that can affect the shape of your dependency tree, such as `--legacy-peer-deps` or `--install-links`, you _must_ provide the same flags to `npm ci` or you are likely to encounter errors. An easy way to do this is to run, for example, `npm config set legacy-peer-deps=true --location=project` and commit the `.npmrc` file to your repo.
43
44 ### Example
45
46 Make sure you have a package-lock and an up-to-date install:
47
48 ```bash
49 $ cd ./my/npm/project
50 $ npm install
51 added 154 packages in 10s
52 $ ls | grep package-lock
53 ```
54
55 Run `npm ci` in that project
56
57 ```bash
58 $ npm ci
59 added 154 packages in 5s
60 ```
61
62 Configure Travis CI to build using `npm ci` instead of `npm install`:
63
64 ```bash
65 # .travis.yml
66 install:
67 - npm ci
68 # keep the npm cache around to speed up installs
69 cache:
70 directories:
71 - "$HOME/.npm"
72 ```
73
74 ### Configuration
75
76 #### `save`
77
78 - Default: `true` unless when using `npm update` where it defaults to `false`
79 - Type: Boolean
80
81 Save installed packages to a `package.json` file as dependencies.
82
83 When used with the `npm rm` command, removes the dependency from `package.json`.
84
85 Will also prevent writing to `package-lock.json` if set to `false`.
86
87 #### `save-exact`
88
89 - Default: false
90 - Type: Boolean
91
92 Dependencies saved to package.json will be configured with an exact version rather than using npm's default semver range operator.
93
94 #### `global`
95
96 - Default: false
97 - Type: Boolean
98
99 Operates in "global" mode, so that packages are installed into the `prefix` folder instead of the current working directory. See [folders](/cli/v8/configuring-npm/folders) for more on the differences in behavior.
100
101 - packages are installed into the `{prefix}/lib/node_modules` folder, instead of the current working directory.
102 - bin files are linked to `{prefix}/bin`
103 - man pages are linked to `{prefix}/share/man`
104
105 #### `global-style`
106
107 - Default: false
108 - Type: Boolean
109
110 Causes npm to install the package into your local `node_modules` folder with the same layout it uses with the global `node_modules` folder. Only your direct dependencies will show in `node_modules` and everything they depend on will be flattened in their `node_modules` folders. This obviously will eliminate some deduping. If used with `legacy-bundling`, `legacy-bundling` will be preferred.
111
112 #### `legacy-bundling`
113
114 - Default: false
115 - Type: Boolean
116
117 Causes npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping. If used with `global-style` this option will be preferred.
118
119 #### `omit`
120
121 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production', otherwise empty.
122 - Type: "dev", "optional", or "peer" (can be set multiple times)
123
124 Dependency types to omit from the installation tree on disk.
125
126 Note that these dependencies _are_ still resolved and added to the `package-lock.json` or `npm-shrinkwrap.json` file. They are just not physically installed on disk.
127
128 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
129
130 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
131
132 #### `strict-peer-deps`
133
134 - Default: false
135 - Type: Boolean
136
137 If set to `true`, and `--legacy-peer-deps` is not set, then _any_ conflicting `peerDependencies` will be treated as an install failure, even if npm could reasonably guess the appropriate resolution based on non-peer dependency relationships.
138
139 By default, conflicting `peerDependencies` deep in the dependency graph will be resolved using the nearest non-peer dependency specification, even if doing so will result in some packages receiving a peer dependency outside the range set in their package's `peerDependencies` object.
140
141 When such and override is performed, a warning is printed, explaining the conflict and the packages involved. If `--strict-peer-deps` is set, then this warning is treated as a failure.
142
143 #### `package-lock`
144
145 - Default: true
146 - Type: Boolean
147
148 If set to false, then ignore `package-lock.json` files when installing. This will also prevent _writing_ `package-lock.json` if `save` is true.
149
150 This configuration does not affect `npm ci`.
151
152 #### `foreground-scripts`
153
154 - Default: false
155 - Type: Boolean
156
157 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.
158
159 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
160
161 #### `ignore-scripts`
162
163 - Default: false
164 - Type: Boolean
165
166 If true, npm does not run scripts specified in package.json files.
167
168 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.
169
170 #### `audit`
171
172 - Default: true
173 - Type: Boolean
174
175 When "true" submit audit reports alongside the current npm command to the default registry and all registries configured for scopes. See the documentation for [`npm audit`](/cli/v8/commands/npm-audit) for details on what is submitted.
176
177 #### `bin-links`
178
179 - Default: true
180 - Type: Boolean
181
182 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
183
184 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.
185
186 #### `fund`
187
188 - Default: true
189 - Type: Boolean
190
191 When "true" displays the message at the end of each `npm install` acknowledging the number of dependencies looking for funding. See [`npm fund`](/cli/v8/commands/npm-fund) for details.
192
193 #### `dry-run`
194
195 - Default: false
196 - Type: Boolean
197
198 Indicates that you don't want npm to make any changes and that it should only report what it would have done. This can be passed into any of the commands that modify your local installation, eg, `install`, `update`, `dedupe`, `uninstall`, as well as `pack` and `publish`.
199
200 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
201
202 #### `workspace`
203
204 - Default:
205 - Type: String (can be set multiple times)
206
207 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.
208
209 Valid values for the `workspace` config are either:
210
211 - Workspace names
212 - Path to a workspace directory
213 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
214
215 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.
216
217 This value is not exported to the environment for child processes.
218
219 #### `workspaces`
220
221 - Default: null
222 - Type: null or Boolean
223
224 Set to true to run the command in the context of **all** configured workspaces.
225
226 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
227
228 - 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.
229
230 This value is not exported to the environment for child processes.
231
232 #### `include-workspace-root`
233
234 - Default: false
235 - Type: Boolean
236
237 Include the workspace root when workspaces are enabled for a command.
238
239 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.
240
241 This value is not exported to the environment for child processes.
242
243 #### `install-links`
244
245 - Default: false
246 - Type: Boolean
247
248 When set file: protocol dependencies that exist outside of the project root will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
249
250 ### See Also
251
252 - [npm install](/cli/v8/commands/npm-install)
253 - [package-lock.json](/cli/v8/configuring-npm/package-lock-json)