Special offer
popup-offers
English
+370 5 205 5502 sales@monovm.com

How to Update NPM

After the introduction of JavaScript, developers got the advantage of creating websites and web-based applications efficiently. It offers numerous resources and libraries to make the development job much more comfortable. In the beginning, it was easier and efficient to maintain this wide range of libraries, but with time we needed a mature solution to handle them. 

11 May, 21 by Antoniy Yushkevych 7 min Read

A Detailed Tutorial on How to Update Node Package Manager (NPM)

It is when NPM (Node Package Manager) was introduced as a JavaScript package manager commonly used in conjunction with Node.js. It allows you to control your project’s dependencies and offers you an excellent way to contribute to the open-source world.

 

What is NPM (Node Package Manager)?

NPM stands for Node Package Manager and is written in JavaScript that is considered to be the default package manager for Node.js. It was developed and maintained by Isaac Z. Schlueter on January 12, 2010. NPM helps manage all the Node.js’s packages and modules and comes along with a command-line client called npm. Whenever you install Node.js, npm also gets installed with it. You can install the required packages and modules of Node.js using NPM.

A package comes with all the files that are needed for a module. These modules are the JavaScript libraries that you can include in the Node.js project as per the project requirement. You can install NPM dependencies for a project using the package.json file. It allows you to update and uninstall packages if not required. If you consider the package.json file, each dependency has specified some range of valid versions for which it will work through a semantic versioning scheme. It helps the developers to auto-update the packages along with avoiding unwanted breaking changes.

Npm helps manage the packages that are a local dependency of a specific project and for globally-installed JavaScript tools. Npm not only manages the direct downloads but also manages the versioning. It allows you to install any version, either previous or later depending on your project requirement. If you do not mention any version to install, it will install the latest package version by default.

Below are some essential facts about NPM you should know.

  • As of now, there are more than 1.3 million OS packages available in the NPM main registry. The registry does not impose any vetting process while submitting, which means these packages can be of low quality, less secure, and harmful to the system. If you want to take down the malicious packages, it is done via user reports. 
  • NPM is open-source.
  • Npm is the recommended functionality in the Node.js installer and consists of the command-line client for interacting with the remote registry.

 

Usage of NPM (Node Package Manager)

Below is the common usage of npm:

  • It helps you adapt the code packages for your applications or incorporate the existing packages as they are.
  • It enables you to download and install the standalone tools to be used right away without any effort.
  • It allows you to run packages without the need to download with the help of npx.
  • You can share your code with another npm user anywhere, irrespective of the underlying system specifications.
  • It allows restricting the code to a particular developer, ensuring the code integrity.
  • It allows you to create organizations that help coordinate the maintenance of packages, coding, and developers.
  • You can also create virtual teams with the help of an organization.
  • It allows you to handle multiple code versions and their dependencies.
  • It allows you to update the application effortlessly and seamlessly whenever the underlying code is changed.
  • You will be able to solve the same problem with several different solutions.
  • It allows you to get in touch with other developers working on the same problems and projects.

 

Components of NPM

There are three main components of npm:

  • Website: you can go to the npm official website, find packages, documentation on npm. It allows you to share and publish packages at the site.
  • Registry: npm has a registry that is an extensive database of millions of packages. Any developer can download the packages from this registry and can publish their customized packages to the registry.
  • CLI: with the help of CLI, you can interact with the npm. It allows you to install, update, uninstall the packages and manage the dependencies.

 

How to Install Node?

Below are some important commands that help in installing the npm. Before updating the version, we will go through the process of installing the npm.

However, npm comes as a part of Node.js, and you do not have to install it explicitly. If you want to install Node.js, you can navigate to the official site for the download. Once you install the Node, you can check the installed version of a node using the below commands.

node -v

npm -v

 

How to Update NPM (Node Package Manager)

If you want to update the NPM, it means you are updating the package manager, Node.js, and modules to the latest version. 

npm update [-g] [<pkg>...]

Where g stands for global and pkg stands for the package.

Using Update Command

You can use the npm update command for updating the node package manager.

npm update -g

Using npm@latest Command

You can use the npm@latest command for updating the node package manager. This command will also work for the Linux system.

npm install npm@latest -g

Using npm@next Command

You can use the npm@next command for updating the node package manager. This command will also work for the Linux system.

npm install -g npm@next

 

Updating on Linux system

Using PPA repository

You can run any of the below commands for updating the node package manager on the Linux system.

sudo add-apt-repository ppa:chris-lea/node.js

sudo apt-get update

sudo apt-get install nodejs npm

Using Cache Cleaning and Installing Stable NPM Version

Run all the following commands step-by-step to install the stable release.

sudo npm cache clean -f

sudo npm install -g n

sudo n stable

 

Updating on Windows

For updating npm, open the PowerShell with the admin account and run the following commands.

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

npm install -g npm-windows-upgrade

npm-windows-upgrade

After running the commands, you will be asked to select an NPM version to install. You can use the arrow key to move upward and downward for selecting the version and hit enter.

If your upgrade process went successful, you would get the below output-

 

Conclusion 

Node.js has become popular for creating interactive websites and web-based applications. It comes with npm (Node Package Manager) that helps manage the packages, modules, and dependencies of Node.js. You must use the latest stable version of the npm for your products to experience the latest functionalities. You can use Node.js and npm on any system, Windows, and Linux. You do not have to worry about installing npm explicitly as it comes with the Node.js installation.

In the above article, we have mentioned some commands that will help you to update the existing npm to the latest stable version. 

Antoniy Yushkevych

Master of word when it comes to technology, internet and privacy. I'm also your usual guy that always aims for the best result and takes a skateboard to work. If you need me, you will find me at the office's Counter-Strike championships on Fridays or at a.yushkevych@monovm.com