View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All

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

By Pavan Vadapalli

Updated on Mar 26, 2025 | 16 min read | 108.9k views

Share:

Did you know that 22 million new project management jobs are expected to be created by 2027? In this high-potential field that demands efficiency and reliability, understanding and properly installing devDependencies in npm have become a must. 

Software development involves countless libraries and frameworks for testing, bundling, and code quality checks. DevDependencies are the add-ons you only need while building or refining an application. Keeping them separate from standard dependencies helps your production environment stay slim and stable.

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!

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"
}

Learn how you can manage development dependencies to keep your projects running smoothly. Enroll in upGrad’s Management Courses to master project management and effectively handle project dependencies.

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

Coverage of AWS, Microsoft Azure and GCP services

Certification8 Months
View Program

Job-Linked Program

Bootcamp36 Weeks
View Program

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?

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.

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

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]

How Can upGrad Help You Master Development Tools?

Development tools and devDependencies play a crucial role in ensuring efficient and high-performing projects. Mastering essential tools and techniques can open doors to promising careers in fields like DevOps and project management.

upGrad offers comprehensive courses in project management and DevOps that can help you prepare for roles in these fields.

Here are some courses of the most popular courses you can try:

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:

Boost your career with our popular Software Engineering courses, offering hands-on training and expert guidance to turn you into a skilled software developer.

Master in-demand Software Development skills like coding, system design, DevOps, and agile methodologies to excel in today’s competitive tech industry.

Stay informed with our widely-read Software Development articles, covering everything from coding techniques to the latest advancements in software engineering.

Reference Link:
https://www.pmi.org/learning/careers/job-growth

Frequently Asked Questions

1. What is the full form of npm?

2. Does npm install dev dependencies by default?

3. How to install npm run dev?

4. How to install nodemon as dev dependency?

5. Does npm CI install dev dependencies?

6. How to check npm install in CMD?

7. Which path to run npm install?

8. Should I use npm CI or npm install?

9. How to run npm in the terminal?

10. What is the difference between npm run dev and npm run production?

11. How do I remove dev dependencies?

Pavan Vadapalli

899 articles published

Get Free Consultation

+91

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

India’s #1 Tech University

Executive PG Certification in AI-Powered Full Stack Development

77%

seats filled

View Program

Top Resources

Recommended Programs

upGrad

AWS | upGrad KnowledgeHut

AWS Certified Solutions Architect - Associate Training (SAA-C03)

69 Cloud Lab Simulations

Certification

32-Hr Training by Dustin Brimberry

View Program
upGrad

Microsoft | upGrad KnowledgeHut

Microsoft Azure Data Engineering Certification

Access Digital Learning Library

Certification

45 Hrs Live Expert-Led Training

View Program
upGrad

upGrad KnowledgeHut

Professional Certificate Program in UI/UX Design & Design Thinking

#1 Course for UI/UX Designers

Bootcamp

3 Months

View Program