1 ---
2 title: npm-ci
3 section: 1
4 description: Clean install a project
5 github_repo: npm/cli
6 github_branch: release/v9
7 github_path: docs/lib/content/commands/npm-ci.md
8 redirect_from:
9 - /cli-documentation/v9/ci
10 - /cli-documentation/v9/cli-commands/ci
11 - /cli-documentation/v9/cli-commands/npm-ci
12 - /cli-documentation/v9/commands/ci
13 - /cli-documentation/v9/commands/npm-ci
14 - /cli-documentation/v9/npm-ci
15 - /cli/v9/ci
16 - /cli/v9/cli-commands/ci
17 - /cli/v9/cli-commands/npm-ci
18 - /cli/v9/commands/ci
19 - /cli/v9/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/v9/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 #### `install-strategy`
77
78 - Default: "hoisted"
79 - Type: "hoisted", "nested", "shallow", or "linked"
80
81 Sets the strategy for installing packages in node_modules. hoisted (default): Install non-duplicated in top-level, and duplicated as necessary within directory structure. nested: (formerly --legacy-bundling) install in place, no hoisting. shallow (formerly --global-style) only install direct deps at top-level. linked: (experimental) install in node_modules/.store, link in place, unhoisted.
82
83 #### `legacy-bundling`
84
85 - Default: false
86 - Type: Boolean
87 - DEPRECATED: This option has been deprecated in favor of `--install-strategy=nested`
88
89 Instead of hoisting package installs in `node_modules`, install packages in the same manner that they are depended on. This may cause very deep directory structures and duplicate package installs as there is no de-duplicating. Sets `--install-strategy=nested`.
90
91 #### `global-style`
92
93 - Default: false
94 - Type: Boolean
95 - DEPRECATED: This option has been deprecated in favor of `--install-strategy=shallow`
96
97 Only install direct dependencies in the top level `node_modules`, but hoist on deeper dependencies. Sets `--install-strategy=shallow`.
98
99 #### `omit`
100
101 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production', otherwise empty.
102 - Type: "dev", "optional", or "peer" (can be set multiple times)
103
104 Dependency types to omit from the installation tree on disk.
105
106 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.
107
108 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
109
110 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
111
112 #### `strict-peer-deps`
113
114 - Default: false
115 - Type: Boolean
116
117 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.
118
119 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.
120
121 When such an 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.
122
123 #### `foreground-scripts`
124
125 - Default: false
126 - Type: Boolean
127
128 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.
129
130 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
131
132 #### `ignore-scripts`
133
134 - Default: false
135 - Type: Boolean
136
137 If true, npm does not run scripts specified in package.json files.
138
139 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.
140
141 #### `audit`
142
143 - Default: true
144 - Type: Boolean
145
146 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/v9/commands/npm-audit) for details on what is submitted.
147
148 #### `bin-links`
149
150 - Default: true
151 - Type: Boolean
152
153 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
154
155 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.
156
157 #### `fund`
158
159 - Default: true
160 - Type: Boolean
161
162 When "true" displays the message at the end of each `npm install` acknowledging the number of dependencies looking for funding. See [`npm fund`](/cli/v9/commands/npm-fund) for details.
163
164 #### `dry-run`
165
166 - Default: false
167 - Type: Boolean
168
169 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`.
170
171 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
172
173 #### `workspace`
174
175 - Default:
176 - Type: String (can be set multiple times)
177
178 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.
179
180 Valid values for the `workspace` config are either:
181
182 - Workspace names
183 - Path to a workspace directory
184 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
185
186 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.
187
188 This value is not exported to the environment for child processes.
189
190 #### `workspaces`
191
192 - Default: null
193 - Type: null or Boolean
194
195 Set to true to run the command in the context of **all** configured workspaces.
196
197 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
198
199 - 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.
200
201 This value is not exported to the environment for child processes.
202
203 #### `include-workspace-root`
204
205 - Default: false
206 - Type: Boolean
207
208 Include the workspace root when workspaces are enabled for a command.
209
210 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.
211
212 This value is not exported to the environment for child processes.
213
214 #### `install-links`
215
216 - Default: false
217 - Type: Boolean
218
219 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.
220
221 ### See Also
222
223 - [npm install](/cli/v9/commands/npm-install)
224 - [package-lock.json](/cli/v9/configuring-npm/package-lock-json)