• Home
  • Blog
  • General
  • How to Install Dev Dependencies in npm? A Complete Guide to Dependencies & Scripts

How to Install Dev Dependencies in npm? A Complete Guide to Dependencies & Scripts

By Pavan Vadapalli

Updated on Jun 24, 2026 | 16 min read | 116.03K+ views

Share:

To install development dependencies in npm, use the npm install <package-name> --save-dev command or its shorthand version, npm install <package-name> -D. These packages are required only during development for tasks such as testing, linting, code formatting, bundling, and debugging, and are not included in the production environment. Examples of common dev dependencies include ESLint, Prettier, Jest, Webpack, Babel, and Nodemon.

In this blog, you’ll learn how to install dev dependencies in npm and how they compare with other dependencies. You’ll also discover alternative methods and tips for managing them effectively. Dive in!

Transform your career with upGrad’s Data Science Course. Learn from industry experts, work on hands-on projects, and gain the skills top employer’s demand.

What Are Development Dependencies?

Development dependencies (known as devDependencies) are tools and libraries needed during the development phase of a project but not necessary in the final production build. These include testing frameworks, transpilers, linters, and bundlers.

devDependencies are listed in the package.json file under the "devDependencies" section. They can be installed using package managers like npm or Yarn to streamline tasks like code testing and compiling.

You can add devDependencies using the following npm commands.

npm install eslint --save-dev

This command will add eslint as a devDependency and update your package.json file.

"devDependencies": {
  "eslint": "^8.0.0"
}

Now that you're familiar with development dependencies, let's explore how to install dev dependencies in npm.

Also Read: How to Check npm Version: A Comprehensive Guide

How to Install Dev Dependencies in npm? A Step-by-Step Approach

You can install devDependencies with npm using two methods: 

  • Using terminal commands with OS-specific considerations
  • Manually editing the package.json file.

Here’s the breakdown of both these methods for installing devDependencies.

1. How to Install Dev Dependencies in npm Using Terminal Commands?

You can use terminal commands to install a module as a development dependency. 

Here’s how to install it on various operating systems.

  • Windows

Open Command Prompt or PowerShell and run the following command:

npm install mocha --save-dev

Open the terminal and run the same command as above:

npm install gulp --save-dev

This command will add a specified module under the devDependencies section in package.json. Here’s what it will look like:

"devDependencies": {
  "mocha": "^10.0.0",
 "gulp": "^4.0.0"
}

Also Read: How to Install Node.js and npm on Windows? [Step-by-Step]

2. How to Install Dev Dependencies in npm by Manually Editing the package.json File?

Perform the following steps to install dependencies manually:

  • Open your project’s package.json file in a text editor.
  • Add the devDependencies section if it doesn’t exist using the following code:
"devDependencies": {
    "mocha": "^10.0.0",
  "gulp": "^4.0.0"
}
  • Save the file
  • Run the following command to install all dependencies, including the manually added ones:
npm install

How Can You Install a Specific Version of a Dev Dependency?

A situation might arise where you need to pin down a precise version of a devDependency rather than always using the latest release. This ensures consistent builds across different environments, helps prevent unexpected breaking changes, and makes debugging easier by locking in predictable behavior.

Let’s understand the implementation through an example.

Example: Installing a Specific Version of ESLint

Below is a step-by-step walkthrough for installing ESLint at version 7.7.0 as a devDependency.

Step 1: Open Your Project Directory

Navigate to your Node.js project folder in the terminal using this command:

cd /path/to/your-project

Step 2: Install a Specific Package Version

Use the @version notation to specify which version you need:

npm install eslint@7.7.0 --save-dev
  • eslint is the package name.
  • @7.7.0 indicates the exact version to install.
  • --save-dev (or -D) ensures it goes into your devDependencies section.

Step 3: Verify the Installation

  • Check package.json: ESLint should be listed under devDependencies with version 7.7.0.
  • Check Installed Packages: Use the command listed below to do so:
npm list --dev
  • This will confirm that ESLint 7.7.0 is now present in your devDependencies.

Step 4: Test Your Setup

Run your ESLint command or script to ensure everything functions properly:

npx eslint --version
  • This should display v7.7.0, verifying you have pinned the correct release.

Specifying the version during installation allows you to maintain a controlled and stable development environment that reduces compatibility surprises.

Also Read: How to Install a Specific Version of an npm Package?

Recommended Courses to upskill

Explore Our Popular Courses for Career Progression

360° Career Support

Executive Diploma12 Months
background

O.P.Jindal Global University

MBA from O.P.Jindal Global University

Live Case Studies and Projects

Master's Degree12 Months

How Do You View and Verify Installed Dev Dependencies with npm?

Observing and confirming the devDependencies present in your Node.js project is essential for maintaining a stable and predictable development environment. npm offers built-in commands and straightforward methods to help you inspect which devDependencies are installed, along with their specific versions.

Below are five key ways to check and confirm your devDependencies:

1. Use the npm list --dev Command

The quickest way to see all devDependencies installed in your project is by running this command:

npm list --dev

Output

This displays each development dependency nested beneath your project’s name. If you need a simpler, top-level view without nested sub-dependencies, add --depth=0:

npm list --dev --depth=0

Why Does It Help? 

It quickly confirms that the devDependencies you expect (like eslint and jest) are currently installed, and shows their installed versions.

2. Check the package.json File

Your package.json file explicitly lists all dependencies for your project.

  • Location: In the root of your Node.js project.
  • devDependencies Section:
{
  "devDependencies": {
    "eslint": "^7.7.0",
    "jest": "^29.4.2"
  }
}

Why Does It Help?

This is your project’s “source of truth”. Even if someone else added or removed a devDependency, this file reflects the intended devDependencies.

3. Confirm Consistency with npm outdated --dev

Sometimes, devDependencies installed locally may differ in version from what’s declared in package.json. You can quickly verify if your installed packages match what’s declared, or if newer versions are available using this command:

npm outdated --dev

Output

It lists each devDependency, the current installed version, and the wanted (or latest) versions.

Why Does It Help? 

It ensures you’re aware of any mismatches or pending updates, especially when working with a team.

4. Double-Check Environment Flags

If you suspect some devDependencies aren’t installed, the following environment-related npm flags might be the reason:

Flag 1

NODE_ENV: If set to production, npm will skip devDependencies by default.

  • Checkecho $NODE_ENV
  • Setexport NODE_ENV=development && npm install

Flag 2

--production: Running npm install --production omits devDependencies.

  • Disablenpm install --production=false

By verifying these flags, you can confirm whether you’re in a state that includes all development tools.

5. Cross-Reference with Your Node Modules

Finally, you can manually inspect your node_modules folder or run this command:

npm list <package-name>

Why Does it Help? 

It confirms that a specific dependency is physically present in your project. If it's missing, you might need to reinstall it or adjust environment flags.

Key Takeaways

  1. npm list --dev offers a live snapshot of every devDependency installed.
  2. package.json is the single source of truth for both dependencies and devDependencies.
  3. Tools like npm outdated --dev keep you informed of updates and mismatches.
  4. Environment flags can affect whether devDependencies are installed.
  5. Combining these approaches ensures your local environment accurately reflects your project’s declared devDependencies.

By following these steps, you'll have a solid grasp of which development tools and libraries your project is using. This will ultimately help you avoid versioning surprises and maintain a smoother development process.

What Are the Alternatives to npm for Managing Development Dependencies?

While npm is widely used for managing development dependencies, several alternative tools offer support for development needs, such as handling large projects or enabling real-time updates.

Here’s a list of alternative tools to npm for installing devDependencies:

  • Yarn: Yarn is a popular tool known for its speed and reliability. It offers faster installations, efficient caching, and offline support for managing dependencies. It is suitable for projects where speed and stability are priorities.
  • Nx: Nx is a build framework designed for monorepos and supports shared dependencies across multiple projects. It has features like graph visualization, caching for builds, and optimized workflows for multi-project repositories. It is suitable for managing interconnected projects in a single repository.
  • Pnpm: Performance npm (Pnpm) is a fast, disk-efficient package manager. It uses a content-addressable storage mechanism to link shared dependencies, reducing disk space usage. It is ideal for teams managing large projects with shared dependencies.
  • Webpack Dev Server: This development server is bundled with Webpack and facilitates real-time updates. It has features like hot-reloading and automatic rebuilds, which makes it suitable for projects requiring frequent front-end updates and testing during development.
  • Lerna: It is a tool to manage JavaScript projects with multiple packages in a monorepo. For multi-package projects, it simplifies dependency management, versioning, and publishing. It is ideal for projects with interconnected packages that need centralized control.

Learn how to manage dependencies using tools like npm, Yarn, and Nx by joining upGrad's Free Certificate Course, Introduction to Product Management.

Also Read: Yarn vs npm: Key Differences and How to Choose the Right Package Manager in 2025

What’s the Difference Between Dependencies and devDependencies?

Understanding the difference between dependencies and devDependencies will help you determine whether a package is needed for the application to run in production or only required during development. 

Here’s how dependencies differ from devDependencies.

Dependencies devDependencies
Packages that are needed for the application to run in production. These packages are only needed during the development phase.
Used specifically in the runtime environment.  Used for testing, building, or linting the code.
Included in the production build and deployed with the application. Not part of the production build. It is used only during development.
Installed with npm install <package> or added under "dependencies". Installed with npm install <package> --save-dev or under "devDependencies".
Examples: Express, Axios, and Lodash. Examples: Mocha, Webpack, and ESLint.

Now that you understand the difference between dependencies and devDependencies, let’s learn how to use npm scripts to enhance the development process.

Subscribe to upGrad's Newsletter

Join thousands of learners who receive useful tips

Promise we won't spam!

How Can npm Scripts Streamline Your Development Process?

You can automate repetitive tasks such as testing, building, and linting using npm scripts. As a developer, you can easily execute tasks with a single command by defining these scripts in the package.json file.

Here are some examples of npm scripts for the development process.

1. Test Script

It is used to automate running test cases. Here’s how the Test Script is defined in the package.json file:

"scripts": {
  "test": "mocha"
}

You can run the Test Script with the following command:

npm run test

2. Lint Script

This script is used for automating code linting to ensure coding standards are followed. Here’s how Lint Script is defined in the package.json file:

"scripts": {
  "lint": "eslint ."
}

You can run the Lint Script using the following command:

npm run lint

3. Build Script

The Build Script is used to automate the process of bundling or compiling code. Here’s how the Build Script is defined in the package.json file:

"scripts": {
  "build": "webpack --mode production"
}

You can run the Build Script using the following command:

npm run build

Now, let’s explore how to update and remove unnecessary devDependencies using npm commands.

Also Read: Introduction to Package JSON Scripts in Node.js

How to Update and Remove Development Dependencies?

Regular updating ensures that the project is compatible with the latest features and security patches while removing unused dependencies, which makes the project lightweight and organized. 

Here’s how you can update and remove devDependencies with npm commands. 

1. Updating devDependencies

The following command updates to the latest compatible versions and saves the changes in the package.json file:

npm update --save-dev eslint webpack

2. Removing devDependencies

Removing unused devDependencies will keep the project lightweight. The following command removes the unnecessary dependencies and updates the package.json file:

npm uninstall @babel/core

How Do You Reinstall Dev Dependencies or Update Them All at Once?

Sometimes, your devDependencies become outdated, misaligned, or corrupted, especially if you’re working on a team or frequently switching environments. Reinstalling or bulk-updating these packages ensures everyone is on the same page and helps you avoid unexpected build or testing errors.

Let’s understand this through a step-by-step example demonstration.

Step 1: Check Your Current Dev Dependencies

Before you do any reinstallation or bulk updates, get a snapshot of what’s installed using this command:

npm list --dev

This helps confirm which devDependencies are currently present and their versions.

Step 2: (Optional) Remove node_modules and Lock Files

If you suspect major conflicts or corruption, the safest route is to start fresh using this command:

rm -rf node_modules
rm package-lock.json
  • node_modules folder is where all installed packages reside.
  • package-lock.json locks specific versions. Removing it forces npm to generate a new lock file from package.json.

Step 3: Reinstall All Dev Dependencies

Simply run this command:

npm install
  • This installs every dependency (both production and dev) as specified in package.json.
  • If you only want to install devDependencies (not typical for local dev, but sometimes useful), you can do this:
npm install --only=dev

Step 4: Update Dev Dependencies

If you want to bring all devDependencies up to their latest compatible versions, use this command:

npm update --save-dev
  • --save-dev ensures these new versions are reflected in the devDependencies section of your package.json.
  • To update a single package, specify its name:
npm update jest --save-dev

Step 5: Validate the Updated Environment

After everything reinstalls or updates, you must do the following things:

  • Check Versions: Use this command:
npm list --dev --depth=0
  • Run Tests or Builds: Validate your setup to confirm the new versions work correctly.

Why Do Reinstallation or Bulk Updates Matter?

  • Consistency: Ensures all teammates use the same dev tool versions.
  • Fresh Start: Removes any leftover artifacts or corrupted packages in node_modules.
  • Security: Pulls in patches and improvements to keep your development environment stable and secure.

By methodically removing old packages and then installing or updating them in bulk, you’ll maintain a reliable, up-to-date workspace that streamlines your development workflow.

What to Do if You Can't Install Dev Dependencies?

You may face difficulty installing devDependencies due to specific environment settings or misconfigurations, such as package issues. 

Here are some of the common reasons for failure and the solutions to overcome them:

  • Production Environment Settings

In the production environment, devDependencies are usually excluded. You may need to include them explicitly using the --only=dev flag.

npm install --only=dev
  • Misconfigured --production Flag

If the --production flag is set to true, you may face difficulty in installing devDependencies. Set the flag to false during installation to include devDependencies.

npm install --production=false
  • Corrupt or Missing package.json File

A missing or corrupted package.json may prevent devDependencies from being installed. You need to verify the file or initialize a new npm package if required.

npm init -y
  • Dependency Conflicts or Registry Issues

Installation can fail if there are conflicting dependencies or issues with the npm registry. You’ll have to clear the npm cache and retry.

npm cache clean --force && npm install

How Do You Force-Install Dev Dependencies When Conflicts Arise?

Even well-managed projects can face dependency or peer-dependency conflicts that prevent certain devDependencies from installing. In these scenarios, npm provides force-install flags to help override or bypass these restrictions, ensuring you can proceed without completely overhauling your setup.

Here’s a step-by-step guide on what you should do and how:

Step 1: Check Your Conflict Errors
Run a normal npm install or npm install --save-dev <package> to see the specific error messages. Identifying the exact conflict helps you decide whether forcing the installation is safe.

Step 2: Use the --force Flag
Apply --force (or -f) if you need to bypass version conflicts or warnings:

npm install <package> --force

This command compels npm to proceed with installation despite errors or peer-dependency warnings.

Step 3: Try --legacy-peer-deps for Peer-Dependency Issues

If the conflict arises from peer-dependencies, run this command:

npm install <package> --legacy-peer-deps

This tells npm to ignore modern peer-dependency enforcement rules, often resolving complex legacy setups.

Step 4: Validate Installation

Confirm that your devDependency is present using this command:

npm list --dev

If you still see errors or missing packages, check whether the forced install caused any unexpected version mismatches.

Step 5: Proceed with Caution

Forcing installations can create hidden version mismatches or break other packages. Always retest or rebuild after forcing an install to ensure everything works together as expected.

Also Read: How to Get List of Globally Installed Packages of npm

npm Dev Dependencies Cheat Sheet

Task Command
Install a Dev Dependency npm install <package-name> --save-dev
Install Using Shorthand npm install <package-name> -D
Install Multiple Dev Dependencies npm install eslint prettier jest -D
Install a Specific Version npm install eslint@8.57.0 -D
View All Dev Dependencies npm list --dev
View Top-Level Packages Only npm list --dev --depth=0
Update All Dev Dependencies npm update --save-dev
Update a Specific Package npm update eslint --save-dev
Remove a Dev Dependency npm uninstall eslint --save-dev
Check Outdated Packages npm outdated --dev
Reinstall All Dependencies npm install
Install Only Dev Dependencies npm install --only=dev
Force Install Despite Conflicts npm install <package-name> --force
Ignore Peer Dependency Issues npm install <package-name> --legacy-peer-deps
Verify Installed Package Version npm list <package-name>

This cheat sheet covers the most commonly used npm commands for installing, updating, managing, and troubleshooting dev dependencies in Node.js projects.

What Are the Best Practices for Managing Dev Dependencies?

Efficient management of devDependencies will ensure a stable, secure, and maintainable project. 

Here are some of the best practices that will optimize the development environment, avoid conflicts, and reduce unnecessary overhead in your projects:

  • Minimize unnecessary dependencies: Include only those dependencies that are absolutely necessary for development tasks like testing, linting, or building.
  • Use version pinning for stability: Make sure you pin specific versions of devDependencies in the package.json file to ensure consistent builds across different environments.
  • Regularly clean unused dependencies: Carry out regular audits and remove unused devDependencies to keep the project lightweight and reduce potential issues.
  • Keep development dependencies local: Install devDependencies on an individual project basis to avoid conflicts with global dependencies and ensure reproducibility.
  • Automate dependency management: Make use of tools like npm outdated or GitHub Dependabot to monitor and update devDependencies automatically.

How Can You Keep Your Development Environment Organized and Efficient?

An organized development environment helps maintain project performance, minimize errors, and enhance collaboration. Efficiently managing dependencies is key to achieving these goals. 

Here are some tips to keep your development environment well-structured:

  • Regularly audit dependencies: Review your package.json regularly to identify and clean up unused dependencies. Use tools like npm prune to remove unnecessary modules.
  • Use a .npmrc file: You can use a .npmrc file for maintaining consistent settings, such as registries and cache locations, across all projects.
  • Organize scripts in package.json: Arrange npm scripts to simplify automation for tasks like testing, building, and deployment.
  • Use local installations: Use local installations of dependencies to remove global conflicts and ensure compatibility within your project.
  • Utilize tools for dependency updates: Use tools like Dependabot or npm-check-updates to find out about outdated dependencies and update them efficiently.
  • Keep your Node.js version consistent: Use NVM (Node Version Manager) to maintain consistency in Node.js versions across your development environments.

Also Read: Node JS Free Online Course with Certification [2025]

Conclusion

Understanding how to install dev dependencies in npm is essential for maintaining an organized and efficient development workflow. By separating development tools from production packages, you can keep applications lightweight while ensuring access to testing, linting, building, and debugging utilities during development.

Whether you're working on a small Node.js project or a large-scale application, proper dependency management helps improve collaboration, simplify maintenance, and reduce compatibility issues. Regular updates, dependency audits, and the effective use of npm commands can help you build a more stable and productive development environment.

Do you still need help deciding which courses can help you excel in DevOps? Contact upGrad for personalized counseling and valuable insights. For more details, you can also visit your nearest upGrad offline center.

Similar Blogs You Might Like:

Frequently Asked Question (FAQs)

1. What are dev dependencies in npm?

Dev dependencies are packages required only during development and testing. They support tasks such as linting, bundling, formatting, compiling, and running tests. Tools like ESLint, Prettier, Jest, and Webpack are common examples that help developers maintain code quality without affecting production builds.

2. How do I install Dev dependencies only?

You can install only development packages by running npm install --only=dev. This command is useful when setting up a local development environment and ensures that tools needed for testing, debugging, and code validation are available without installing production-related packages.

3. How to install project dependencies in npm?

To install all packages listed in a project's package.json file, run npm install in the project directory. This command downloads required modules, creates the node_modules folder, and prepares the project environment for development, testing, and deployment activities.

4. Will npm ci install dev dependencies?

Yes, npm ci installs both regular and development packages by default when not running in production mode. It uses the exact versions defined in package-lock.json, making it a preferred choice for continuous integration pipelines and reproducible project setups.

5. What is the difference between dependencies and devDependencies?

Dependencies are packages required for an application to run in production, while devDependencies are needed only during development. Runtime libraries such as Express belong under dependencies, whereas testing, linting, and build tools are typically stored as development dependencies.

6. How do I install dependencies?

Navigate to your project folder and run npm install. npm reads the package configuration file, downloads all required packages, and installs them locally. This command is usually the first step after cloning a repository or setting up a new project.

7. When should a package be added as a development package?

A package should be added as a development dependency if it supports coding, testing, formatting, compiling, or debugging activities. If the application does not require the package to run in production, it generally belongs in the devDependencies section.

8. Installing Dev Dependencies with NPM: What command should I use?

The standard command is npm install <package-name> --save-dev or the shorthand version npm install <package-name> -D. This automatically adds the package to the devDependencies section of the package.json file and installs it locally.

9. How can I check whether a package is installed as a dev dependency?

You can use commands such as npm list --dev or inspect the devDependencies section in package.json. Both methods help verify installed packages, their versions, and whether they are categorized as development tools rather than runtime requirements.

10. How to npm install without dev dependencies?

To skip development packages, use npm install --production or set NODE_ENV=production before installation. This approach is commonly used in production servers where only runtime packages are required to keep deployments smaller and more efficient.

11. What are the most common development tools installed through npm?

Developers frequently install tools such as ESLint, Prettier, Jest, Mocha, Babel, TypeScript, Nodemon, and Webpack. These packages support testing, formatting, code quality checks, compilation, and workflow automation, making software development faster and easier to manage.

Pavan Vadapalli

899 articles published

Pavan Vadapalli is the Director of Engineering , bringing over 18 years of experience in software engineering, technology leadership, and startup innovation. Holding a B.Tech and an MBA from the India...

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

Top Resources

Recommended Programs

upGrad

upGrad

Management Essentials

Case Based Learning

Certification

3 Months

IIMK
bestseller

Certification

6 Months

OPJ Logo
new course

Master's Degree

12 Months