npm Install & Dependencies/Install an optional dependency

Add an optional dependency.

Section: Installing dependencies

Install an optional dependency

bash
bash
npm install -O <package>
Explanation

Add an optional dependency.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Installing dependencies
Install a package
Install a runtime dependency.
OpenIn sheetbashsame section
Install a specific version
Install an exact version.
OpenIn sheetbashsame section
Install a dev dependency
Add a development dependency.
OpenIn sheetbashsame section
Install as peer dependency
Add a peer dependency entry.
OpenIn sheetbashsame section
Install without saving
Install a package without editing package.json.
OpenIn sheetbashsame section
Install globally
Install a CLI tool globally.
OpenIn sheetbashsame section