How to Install Specific Version of NPM Package? (2024)

Since 2009, Node.js has taken over the market and has become popular among developers for creating reliable systems and web-based applications. It has proved to be a boon for the JavaScript developers looking to create complex applications. Node.js has several features, but the core feature is the NPM (node package manager) that has helped JavaScript developers quickly and efficiently share and use packages, such as lodash, moment, and others.

There is no limit on the number of packages available and how many have been downloaded. It lets the developers share and install the code from the package managers. The Node.js syllabus is vast and requires dedication to hone this skill. So, to better understand the working of Node.js and NPM, you must know the installation process. Then you can start creating unique applications.

This article will discuss different methods to NPM install specific version of Node.js packages in detail.

What is NPM?

The NPM (node package manager) is a default package manager for JavaScript runtime Node.js. The NPM has the following main parts-

  • A CLI (command-line interface) allows the developers to publish and download the packages within your project. It lets the developers interact with NPM.
  • It also acts as an online repository well-known for hosting JavaScript packages.
  • The online website allows you to check for the required packages, create different user profiles, and improve the overall NPM experience for developers across the globe.

How to Install Specific Version of NPM Package?

Step 1: Before starting your project, you must ensure that you install the latest version of NPM to leverage all the new functionalities within your project. We first need to run the following command to check if we have NPM installed on my system.

How to Install Specific Version of NPM Package? (1)

Step 2:Now, I can use the node to install a specific version of other packages required within your project. First, we will install the “moment” package as shown below. The Moment.js is a lightweight JavaScript development tool that lets you manipulate date and time.

How to Install Specific Version of NPM Package? (2)

Step 3: Now, to check what version of the “moment” package has been installed, we have to run the “NPM list” command.

How to Install Specific Version of NPM Package? (3)

If you do not mention any version in the command, the NPM will fetch the latest version available. As you can see from the above image that the installed version is 2.29.3. But, there might be some cases where installing the latest packages with new changes can hamper your application, so you might require another version to perform perfectly.

So, what command will work to run the NPM install command with a specific package version? You can use the below command to install specific NPM package version. You can mention the required version number after the package name is separated by the ‘@’ sign.

Step 4: Now install the “2.25.3” version of the moment package. You can run the following command.

npm install [email protected] //npm install specific version

How to Install Specific Version of NPM Package? (4)

The above command will install the package locally. But if you want a global moment package, you can use the “-g” flag with the install command. For example-

npm install -g [email protected]

How to Install Specific Version of NPM Package? (5)

Step 5: When installing the global package, you need admin access. As you can see, we have used sudo access to run the command. To list the global packages, you need to use the “-g” flag with the list command, as shown below.

npm -g list

How to Install Specific Version of NPM Package? (6)

Another example is to install an angular cli specific version. Installing angular-cli will take time.

npm install -g @angular/cli@7

How to Install Specific Version of NPM Package Using Yarn?

Like the NPM install command, you can use the yarn command to add the package to your system. By default, it will install the package from the NPM registry. Else you have to specify another one in your package.json.

  • Also, you can use the yarm command to add the latest version of the NPM package. But first, we need to install the yarn to make it add the new version of the packages.
npm install yarn

How to Install Specific Version of NPM Package? (7)

yarn add package-nameyarn add react // yarn add specific version
  • But if you want to install NPM specific version of the package using the yarn command, then hit the following command.
yarn add [email protected] //yarn install specific version
  • Also, you can replace the tag with eta, next, or latest, as per your package requirement.
yarn add package-name@tag

How to Check Specific Version of NPM Installed Package?

To list all the installed NPM packages, you can use the list command or ls for the short version.

How to Install Specific Version of NPM Package? (8)

It lists all the packages in a tree-like structure along with their dependencies. It is an easier option to check the version simultaneously as it is complex to check versions of packages individually. But, if you want detailed information on the installed NPM packages, you can just access the content of the package-lock.json file.

So run the following command to get the details about packages.

cat package-lock.json

How to Install Specific Version of NPM Package? (9)

To get the list of the top-level packages without displaying their dependencies, you can add the -depth=0 flag. It will limit the search to the package name only.

For example-

npm ls -depth=0

How to Install Specific Version of NPM Package? (10)

To check the globally installed packages, you can use the “-g” flag and the NPM list command. For example-

npm list -g

How to Install Specific Version of NPM Package? (11)

If you want to check the specific version for the installed package, you can hit the following command.

npm list moment

How to Install Specific Version of NPM Package? (12)

The above command has displayed the installed version only for the specific package mentioned.

Whether you are a beginner or an experienced professional, you must learn from the best Full-stack Web Development course available in the market.

How to Install Older Version of NPM Package?

NPM uses the Semantic Versioning Specification, which is the convention rule to stipulate the versioning of the packages. You see three numbers separated by a dot whenever you install a package. As in the case of the installed moment package, it is 2.25.3 representing the major, minor, and patch versions, respectively. The semantic versioning specifies which version of the package to install. If you use a caret (^) character, it will install the minor version. You can use the (~) character to install the latest patch version of the specific package.

This is useful if you do not know the minor or patch version of a specific package that you want to install. You can simply prefix the version number with a caret character.

Also, if you are not sure about the latest minor version of the package with the latest security patches, you just need to prefix the version number with a tilde. For example-:

How to Use Semantic Versioning to Specify Install Versions?

The NPM uses the Semantic Versioning. It is a popular way of versioning the unique stages of the project. It is beneficial as it improves the code’s clarity and readability. If a new developer takes over, he can quickly go through different versions to understand the changes made earlier. It is a simple way to keep track of the changes that have been made.

SemVer represents the version in the format- x.y.z. where-

  • x specifies the major version, including the API changes and backwords incompatibility.
  • Y specifies the minor version, including all the new and latest features implementation, enhanced framework or functionality, and backward compatibility.
  • Z specifies the patch, including bug fixes, hotfixes, maintenance releases, and backward compatibility.

For example, we consider the 2.25.3 version (the latest) of the moment package. It specifies that “2” is the major version, “25” is the minor version, and “3” is the patch version.

Semantic versioning is crucial in helping the developers to keep track of the code and what has changed over time. Also, developers understand the changes and when and where the software has been updated. Not only this, developers can know which version is not backward compatible.

How to Install Node Using 'Homebrew'? [Step-by-Step]

To install the Node with the help of the Homebrew, you need to follow the below steps.

Step 1: First, install the Homebrew on your macOS.

Homebrew is a package manager for macOS that you need to install explicitly. Run the following command from the macOS terminal.

$curl -fsSL -o install.shhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh 

Step 2: Check the installed Homebrew version.

To quickly check the installed version of the Homebrew, run the following command from the terminal.

$ brew -v 

Step 3: Installing node with Homebrew

For installing Node on your macOS using Homebrew, run the following command.

$ brew install node 

Step 4: Check the installed version of Node and NPM

You can check the installed version of Node and NPM using the below command.

$node -v 

Also, use the following command to check the version of the NPM .

$npm -v 

Step 5: Install a specific version of the node

If you specifically want to install a specific version of Node, you can use the following syntax.

$ brew install node@<version_number> 

How to Install Specific Version of NPM Package from GitHub?

  • Install from GitHub Repository: To install a package from a GitHub repository, enter the repository URL followed by theappropriate versionor commit hash.

Example:

npm install github:user/repo#v1.2.3

In this example, replace ‘user’ with your own Github username, ‘repo’ withthe name of the repository, and v1.2.3 with the tag, branch, or commithashyou wish to install.

  • Using Git URLs: For extra control, you can enter the Git URL directly into thenpminstall command, which is very handy for private repositories.

npm install git+https://github.com/user/repo.git#v1.2.3

This method is similar, but it uses the whole Git URL for the repository.

How to Know Package Versions Available?

When dealing with Node Package Manager (NPM), it is critical to understand the available package versions to ensure compatibility and access torequiredfeatures or fixes.Here'sa simple tutorial for tackling this:

  • NPM Registry:The NPM registry is the major source of package information. You can obtain detailed information about a package, including available versions, by visiting the NPM webpage or using the command-line interface (CLI) with commands such as npm search or npm info <your package name>.
  • Package.json:Your project'spackage.jsonfilecontainsa list of dependencies and their version constraints. Runningnpmoutdated can display which dependencies are out of date and which have the most recent versions available. This provides information about which packages require updating.
  • Online Repositories: Many packages are maintained on version control systems like GitHub. Visiting the repository or its releases page can yield a list of available versions. In addition, the GitHub API can be used programmatically to retrieve version information.

How to Use NPM?

Now that we understand what NPM is, the question is how can you use it within your code. As it consists of CLI (command-line interface), we have to run CLI commands to interact with NPM. Below are some basic commands that will help you work with your project.

  • NPM, init: creates the package.json file. If you are working on an application from scratch, it must be the first command that will run. If you install or remove the packages, Node, js will automatically update this file.
  • NPM install: to install the required project dependencies within a package.json file.
  • NPM install <package-name>: install a specific package from the NPM registry and store that package under the node_modules folder.
  • NPM install <package-name> –save: this command will install an NPM package within the dependencies in your package.json file.
  • NPM install <package-name> –save-dev: it will install an NPM package under the devDependencies
  • npm uninstall <package-name>: this command will uninstall a specific package.
  • NPM update <package-name>: it will update a specific package to the available latest version.

Points to be Considered While Working with Node and NPM

Below are some points to consider working with Node and NPM.

  • Ensure to have the latest version of Node installed on your system. If you do not have the latest version, run the following command to install a specific version of the node.
Install node //install specific node version
  • Then install the latest version of npm. If you do not want to work with the latest version, you can specify a specific version to install node and npm. Run the following to install a specific version of npm.
Install npm@<version> //install specific version of npm
  • To install the packages, you must have sudo access to do that.

Looking forPython training near me? Unlock the power of coding with Python, the versatile and in-demand programming language. Start your journey today and become a Python pro!

Conclusion

Node.js has done wonders for JavaScript developers and reduces their challenges by going through several languages. It provides them with a sustainable development environment to use a single language and framework to do all the work.

Node.js lets the developers build web-based applications with two-way connections, including both the server-side and client-side. Node.js has changed the way of pushing the applications in real-time over WebSocket. To central your skills in Node.js, you can refer KnowledgeHut Node.js syllabus.

So, if you are still confused about whether to go for Node.js or not, then there should be no doubt about it. It will make your life easy by streamlining your coding experience.

How to Install Specific Version of NPM Package? (2024)
Top Articles
17 Free Money Websites Where Rich Or Kind People Give Away Free Money
Ubuntu Manpage: fakeroot - run a command in an environment faking root privileges for file manipulation
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 5848

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.