Install Dev Dependencies With npm
Dev dependencies are packages required only for the development phase and not for the application to run in production. Some common examples of such packages are testing frameworks (jest, cypress, karma, mocha), code linters (prettier, eslint), build tools (babel, webpack), and more.
The short answer
To install one or more npm packages as dev dependencies, you can use the npm install command combined with the --save-dev flag as follows:
$ npm install <package_name …> --save-devFor example:
$ npm install jest eslint --save-devAlternatively, you can use the shorthand -D flag (short for development):
$ npm install <package_name> -DAll the npm packages you add using the above flags will be found under the devDependencies section in package.json and automatically installed in the node\_modules folder of your project.

Easily retrieve this command using Warp’s AI Command Search
If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:

Entering npm install dev dependencies in the AI Command Search will prompt an npm command that can then quickly be inserted into your shell by doing CMD+ENTER.
Installing a specific package version
By default, the npm install command installs the latest version of the specified packages. If you want to install a specific version instead, you can use @ followed by the package's version number.
For example:
$ npm install jest@^27.0.0 --save-devInstalling dev dependencies using the package.json
Suppose you want to add multiple packages with specific versions, then adding the package names and versions in the package.json file would be easier than manually installing each package using the npm install <package\_name> command.
"devDependencies": {
"eslint": "^7.7.0",
"eslint-config-prettier": "^6.9.0",
"jest": "^29.4.2"
}Once the package.json file is updated, you can run the npm install command to automatically install all the packages listed under the dependencies and devDependencies sections in the node\_modules folder.
$ npm installInstalling dev dependencies only
To install only the dev dependencies, you can use the npm install command followed by the --only=dev flag:
$ npm install --only=devTroubleshooting common dev dependency installation issues
If you cannot install the devDependencies, cross-check the value of the NODE\_ENV environment variable (commonly used in the Node.js environment). If this value is set to production, then npm will skip the installations of packages listed under the devDependencies. Thus, ensure that the value for NODE\_ENV is set to development.
To verify the value of the NODE\_ENV variable, you can use the echo command as follows:
$ echo $NODE_ENVTo set or update the value of the NODE\_ENV variable, you can use the export command as follows:
$ export NODE_ENV=developmentAlternatively, you can use the following syntax, to locally set the NODE\_ENV variable as development everytime you execute the npm install command, ensuring that both production and development dependencies are installed.
$ NODE_ENV=development npm installReinstalling dev dependencies
Reinstalling or updating or all npm packages follows the same process and commands for both dependencies and devDependencies. Read more about how to reinstall all packages with npm.
To update or re-install only the dev dependencies, you must use the --save-dev flag. This command will update the already installed dev dependencies according to the version ranges defined in the package.json file.
$ npm install --save-devTo update a specific package to the latest version regardless of the version specified in the package.json file, use the npm install command followed by the package name:
$ npm install <package_name> --save-devAlternatively, you can use the npm update command as well:
$ npm update --save-dev
$ npm update <package_name> --save-devTroubleshooting cache issues when updating already installed packages
NPM maintains a cache of downloaded packages to speed up the installations. If you encounter any installation issues, consider clearing the npm cache by using the npm cache command:
$ npm cache clean --forceRelated articles
How To Reinstall Packages With Npm
Brief guide to reinstalling npm packages using npm
List Installed Npm Packages
Learn how to list globally and locally installed packages with npm, including their dependencies.
Check Npm Package Version
Check an npm package version within your project
Install NPM Packages From GitHub
Check an npm package version within your project
Clear npm Cache
Learn how to clear the npm cache on Linux, macOS, and Windows.
Removing npm Packages
Learn how to remove packages locally, globally, and from the registry using the npm uninstall command.
Execute Packages With npx And npm
Discover the power of npm's npx tool, a developer's best friend for running packages without global installs.
Re-Installing Npm
Learn how to reinstall Node.js and npm on macOS, Linux, and Windows using `curl`, `brew`, `apt`, `nvm`, and Node installer.
How To Update NPM
Learn how to update npm to a specific version using the npm, nvm, or npx commands.