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

How to update npm package to latest version? [Complete Guide]

If you are looking to update npm package and don't know how to do that, Then this blog post "How to Update npm package to the latest version" will guide you on how to do that.

25 Jun, 21 by Antoniy Yushkevych 7 min Read

List of content you will read in this article:

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. This article will give you a brief about how to update NPM package?

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.

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 packages, modules that come 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 NPM packages if not required. If you consider the package.json file, each dependency has specified some range of valid NPM 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.

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's 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.

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.

Below are some important commands that help in installing the npm. Before you update NPM 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.

1. Using Update Command

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

npm update -g

2. 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

3. 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

How to update NPM package on Linux?

1. 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

2. 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

How to update NPM version 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-

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 NPM version for your products to experience the latest functionalities. Also, you know after reading this blog how to update NPM packages and how to update NPM version 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 NPM version. 

People are also reading:

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