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

Learn How to Instantly Install a Specific Version of an NPM Package!

By Pavan Vadapalli

Updated on Jul 10, 2025 | 11 min read | 21.91K+ views

Share:

Did You Know? The npm registry is a colossal ocean with over 3 million JavaScript packages as of today? That makes it the world's largest single-language code hub!

To install a specific version of NPM package, use the npm install command followed by the package name and version number, like this: npm install package@version. For front-end developer projects, managing dependencies this way helps maintain consistency, especially when integrating Java-based APIs or microservices into portfolio websites or interactive apps.

This blog will guide you through the steps to install specific NPM versions, check for available versions, and provide tips for effective dependency management.

JavaScript is crucial for scalable apps, and NPM helps manage dependencies. upGrad’s Software Engineering Courses provide training in JavaScript, system architecture, and core programming to build reliable software. Enroll today!

Installing Specific Version of NPM Package Using Command Line

Getting an NPM install-specific version using the command line is a straightforward process. Here’s a step-by-step guide:

  • Open your command-line interface (CLI) or terminal.
  • Navigate to the root directory of your project or the location where you want to install the package.
  • Use the following command to install a node install-specific version:

NPM install <package-name>@<version>

  • Replace <package-name> with the package name you want to install and <version> with your desired specific version. For example:

NPM install lodash@4.17.21

  • This command will install version 4.17.21 of the lodash package.
  • Wait for the installation process to complete. NPM will fetch and install the package’s specified version and dependencies.

Your specific version of an NPM package using the command line is ready now!

Improve your programming skills with courses on tools like NPM, covering techniques to manage dependencies, use AI, and build scalable applications, such as:

After installing, you can also specify the version directly within your project by updating the package.json file.

Also read: Top Front-End Developer Interview Questions for 2025

Installing Specific Version Using package.json File

Installing a specific version of NPM package can also be done by specifying the version directly in your project’s package.json file. This method ensures that your project always installs the exact version you need, even when running npm install on different machines or environments. Here's how you can do it:

  1. Open the package.json file located in the root directory of your project.
  2. Find the dependencies or devDependencies section, depending on whether the package is a production or development dependency.
  3. Add or update the entry for the package with the desired version number. For example:

    "dependencies": {
      "lodash": "4.14.1"
    }

In this example, the lodash package is specified with version 4.14.1. This will ensure that every time you run npm install, the specific version of NPM package you’ve defined will be installed, providing consistency across different setups or team environments.

Coverage of AWS, Microsoft Azure and GCP services

Certification8 Months

Job-Linked Program

Bootcamp36 Weeks
  • Save the package.json file.
  • Open your command-line interface (CLI) or terminal.
  • Navigate to the root directory of your project.
  • Run the following command to install the dependencies:

NPM-install

This command will read the package.json file and install the specified versions of the packages listed in the “dependencies” and “devDependencies” sections

Enhance your career with the Professional Certificate Program in Cloud Computing and DevOps. Gain practical experience with AWS, Azure, and Google Cloud, and master key DevOps tools like Docker and Kubernetes.

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

After updating the package.json file, you can install a specific version using the Yarn CLI.

Install Specific Version of NPM Package using Yarn CLI

The process of installing a specific version of NPM package using Yarn CLI is very simple and ensures you get the exact version you need for your project. Here’s a more detailed explanation of the steps:

  1. Open your command-line interface (CLI) or terminal: This can be done on your local machine or through an integrated terminal in a code editor like VS Code.
  2. Navigate to your project’s root directory: This is where your package.json file is located. If you’re not already in the project directory, use the cd command to navigate to it in your terminal.

To install a specific version of NPM package with Yarn, use the following command format:

yarn add <package-name>@<version>

Replace <package-name> with the name of the package you want to install, and <version> with the specific version number you need. For example, to install version 4.17.21 of the lodash package, you would run:

yarn add lodash@4.17.21
  1. This command tells Yarn to fetch and install exactly version 4.17.21 of lodash.
  2. Wait for the installation process to complete: Once you run the command, Yarn will go out to the npm registry, fetch the specified version of the package, and install it along with any of its dependencies. The installation process will be complete once Yarn updates the node_modules folder and yarn.lock file with the new version.

Using this method, you can easily manage dependencies and ensure your project is using the specific version of NPMpackage that is compatible with your project’s requirements.

Also Read: Full Stack Developer Salary in India 2025: Trends & Top Recruiters

After installing a specific version with Yarn CLI, you can also install a package directly from GitHub for more customized versions.

Install Specific Version of NPM Package from GitHub

To install packages available at GitHub Packages and configure your project to use them, follow these steps:

  • Ensure that you have a package.json file within your project directory. If not, create one. This file will manage your project’s dependencies.
  • Authenticate GitHub Packages using the appropriate authentication method. This step ensures you have permission to access and install packages from GitHub Packages.
  • Create or edit a .NPMrc file within the same directory as the package.json file. Add the following line, replacing NAMESPACE with the account name that owns the repository where your project is hosted:

    @NAMESPACE:registry=https://NPM.pkg.github.com

This configuration sets GitHub Packages as the registry for your project.

  • Add the .NPMrc file to your repository so that GitHub Packages can easily locate and use it.
  • Configure your package.json file to include the specific package you want to install. Define the full-scoped package title for GitHub Packages, such as @my-org/package, or the full name of the packages from NPMjs.com, such as @babel-core or lodash.
  • In the “dependencies” section of your package.json, add the package and define the desired version:

    "dependencies": {
      "ORGANISATION_NAME/PACKAGE_NAME": "1.1.4"
    }
  • Save the changes to your package.json file.
  • Run the following command to install the package and its dependencies:

    $ NPM install

Become a sought-after developer with the 9-month Full Stack Development Course by IIITB. Gain hands-on experience, learn top programming tools, and work on real-world projects. Apply Now to upskill and unlock exclusive job portal access and IIITB alumni status.

Also read: 25+ Essential Machine Learning Projects GitHub with Source Code for Beginners and Experts in 2025

Once you've installed from GitHub, understanding semantic versioning helps manage package versions for better compatibility.

Using Semantic Versioning for Package Versioning

Semantic versioning is a widely used versioning scheme for software packages, including specific version of NPMpackages, that follows the format MAJOR.MINOR.PATCH. Each segment of the specific version of NPM package number represents a specific type of change in the software:

  1. MAJOR version: This number is incremented when you introduce incompatible API changes or major functionality modifications. A change in the specific version of NPM package MAJOR version indicates that the new version may not be backward-compatible with previous versions. Users should be aware that upgrading to this version might require code adjustments.
  2. MINOR version: The MINOR version is incremented when new features or functionality are added, but backward compatibility is maintained with previous versions. This means that users can update to this version without breaking their existing code or functionality.
  3. PATCH version: When you release backwards-compatible bug fixes or minor updates, you increment the PATCH version. This indicates that the new version contains improvements or fixes but does not introduce new features or changes that affect compatibility.

Understanding specific version of NPM package helps developers manage and maintain compatibility when updating dependencies, ensuring that the correct versions are used and that the software works as intended across different environments.

Semantic versioning helps developers and users of a package understand the significance of version updates at a glance. 

When installing packages, you can specify the desired level of version flexibility using semantic versioning operators:

  • ^ (caret)
  • ~ (tilde)
  • = (equal)

You have the flexibility to specify which types of updates your package can accept from its dependencies by using semantic versioning in your package.json file.

To indicate the acceptable version ranges, you can implement the following syntax:

  • For patch releases: Use 1.0 or 1.0.x or ~1.0.4 to allow updates up to version 1.0.4.
  • For minor releases: Use 1 or 1.x or ^1.0.4 to allow updates within the 1.x.x range, but not to version 2.0.0.
  • For major releases: Use * or x to allow any major version updates.

Become an expert in AI-Driven Full-Stack Development with upGrad’s 8-month bootcamp. Gain certifications from Microsoft, NSDC, and upGrad, and enhance your skills with real-world projects. Show Interest now to get sponsorship for Microsoft Azure AI certification, mentorship, and career support.

Also read: What is Agile Software Development? Methodologies & Principles

With semantic versioning in place, let's explore the importance of installing specific versions of NPM packages.

Understanding the Importance of Installing Specific Versions

Installing specific versions of node holds significant importance as it facilitates the distribution of JavaScript code to web and mobile applications while allowing ongoing improvements without requiring users to delete and update their apps.

Let’s understand the importance of installing specific packages –

  • Ensure Code Sharing: Specific version installations enable seamless sharing with other NPM users worldwide, promoting collaboration and accelerating development processes.
  • Version Management: Installing specific versions allows developers to create and manage multiple versions of code, empowering them to test and evaluate different versions to determine the one that works best for their projects.
  • Performance Optimisation: By installing specific versions, developers can easily send minor updates to keep the software running at its optimal performance level, ensuring continuous improvements without disrupting user experiences.
  • Seamless Rollouts: Installing specific NPM versions facilitates the smooth rollout of improvements, allowing developers to introduce enhancements without interrupting or causing damage to the user experience.

Stay competitive in AI-driven software development by upskilling with a Master’s in Artificial Intelligence and Machine Learning from IIIT Bangalore & LJMU. Gain hands-on experience in integrating AI models, chatbots, and automation into applications, while mastering Deep Learning, Generative AI, and NLP.

Let us now have a closer look at some of the best practices for installing NPM packages.

Also read: SDLC Guide: The 7 Key Software Development Life Cycle Phases Explained

Best Practices for Installing Specific Versions of NPM Packages

 

Installing the specific version of NPM package is crucial for maintaining stability, preventing unexpected bugs, and ensuring compatibility across different environments. 

By using the correct specific version of NPM package, you can avoid issues caused by automatic updates or mismatched dependencies. 

Here are some reliable methods and tips to help you install the specific version of NPM packages with confidence:

Checking NPM version:

  • Use npm --version to check the version of the NPM CLI.
  • Use npm list --depth=0 to get detailed version information about NPM, the current package, Node.js, and other direct dependencies.

Getting help:

  • Use npm help <command> to access the built-in help functionality of NPM for any questions regarding commands.

Starting new projects with NPM init:

  • Use npm init --yes to quickly create a package.json file with default values.
  • Set default values for the author name and email using npm config set init.author.name and npm config set init.author.email commands.

Finding NPM packages:

  • Utilize websites like NPMs.io to explore and evaluate NPM packages based on quality, popularity, and maintenance metrics, which helps in finding the specific version of NPM package you need.

Saving dependencies:

  • Install and save a package using npm install <package-name> --save.
  • Configure NPM to save dependencies with different prefixes or exact versions using npm config set save-prefix and npm config set save-exact.

By following these methods, you'll be able to confidently install the specific version of NPM packages, ensuring compatibility and preventing issues in your projects.

Get started with dynamic web development in our React.js for Beginners course. Learn key concepts like the Virtual DOM, ES6 features, and bundling, and build your own Phone Directory app. Perfect for beginners aiming to create responsive, high-performance UIs.

Also Read: Top Full Stack Developer Skills to Master in 2025

Once you've followed best practices for installing specific NPM versions, let's look at how to troubleshoot common installation issues.

 

Learning Installing the Specific Version of NPM Packages with upGrad

To install a specific version of NPM package, use the command npm install [package]@[version]. This ensures project stability and compatibility by preventing unexpected bugs. Make it a habit to specify versions in your package.json file to avoid conflicts and maintain consistency.   

A lot of users face dependency issues when installing NPM packages. upGrad’s courses teach you how to manage specific NPM versions and other advanced techniques, helping you build stable, scalable software with expert guidance.

Feeling unsure about where to begin with your software career? Connect with upGrad’s expert counselors or visit your nearest upGrad offline centre to explore a learning plan tailored to your goals. Transform your programming journey today with upGrad!

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.

References :
https://www.mend.io/wp-content/media/2021/02/1-1-1024x260.png
https://youtu.be/rg5BE2glE6U?t=228
https://user-images.githubusercontent.com/27772165/54670414-e621e480-4af3-11e9-871d-80af39fe32de.png
https://www.youtube.com/watch
https://builtin.com/software-engineering-perspectives/npm

Frequently Asked Questions (FAQs)

1. What is the difference between NPM and Node.js?

2. What’s the difference between npm install and npm ci?

3. What does the --save or --save-dev flag mean in NPM?

4. What is semantic versioning in NPM?

5. What do ^, ~, and * mean in package.json?

6. How can I lock a package version in my project?

7. What is a package-lock.json file and why is it important?

8. How can I update an NPM package to the latest version?

9. What is the purpose of the node_modules folder?

10. Why is npm install so slow, and how can I speed it up?

11. Is it safe to install third-party packages from NPM?

Pavan Vadapalli

900 articles published

Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology s...

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

upGrad KnowledgeHut

upGrad KnowledgeHut

Angular Training

Hone Skills with Live Projects

Certification

13+ Hrs Instructor-Led Sessions

upGrad

upGrad

AI-Driven Full-Stack Development

Job-Linked Program

Bootcamp

36 Weeks