3 Top Node.js Package Managers for Linux

Node.js is one of the most popular programming languages rocking the software development industry in the world over. While developing and using Node.js applications, one common software that developers and general users will always find themselves relying on is a package manager.

A Node.js package manager interacts with online package repositories (that contain Node.js libraries, applications, and related packages) and helps in many ways including package installation and dependency management. Some package managers also feature project management components.

Read Also: 4 Process Managers for Node.js Applications in Linux

For example, if you are writing a web application and realize that a free external library that implements a given functionality within your application already exists in a public repository, you can use a package manager to install it on your system in the applications directory and integrate it with your application.

The package manager also helps to specify the library as a dependency for your application, so that any system where the application is installed, the library will be installed also, for the application to work properly.

In this article, we will review top Node.js package managers that you can install on a Linux system.

1. NPM – Node.js Package Manager

npm needs no introduction in the Node.js ecosystem. But what is npm? npm is a combination of many things really – its a Node package manager, npm Registry, and npm command-line client.

First, npm is a cross-platform Node.js package manager that was developed to help JavaScript developers to easily share their code in the form of packages. To install and publish packages, developers use a command-line client called npm, which is also used for version management and dependency management. It runs on Linux and other UNIX-like systems, Windows, and macOS.

Additionally, npm is also a safe online repository for the publishing of open-source Node.js projects such as libraries and applications. It is one of the most popular and largest open-source software registries on the web. You can use it for free, an option that allows you to create public packages, publish updates, audit your dependencies, and do more.

Read Also: 18 Best NodeJS Frameworks for Developers

Alternatively, you can sign up for npm Pro to enjoy a premium development experience that comes with many benefits such as private repositories. Large development teams working on business-critical projects can opt for npm Enterprise which allows them to develop packages internally that is not shared publicly.

The npm command-line client is distributed with the Node.js package, this means that when you install Node.js on your Linux system, you will automatically get npm installed too. Interestingly, npm is used to install all the other Node.js package manager described below.

npm also supports JavaScript security, integrating npm with third-party tools, such as CI/CD (Continuous Integration/Continuous Delivery) systems, and so much more.

To install the latest version of Node.js and NPM on Linux systems, follow the commands on your respective Linux distribution.

Installing NPM on Debian and Ubuntu

$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
$ sudo apt-get install -y nodejs

Installing NPM on CentOS, RHEL, and Fedora

# curl -sL https://rpm.nodesource.com/setup_14.x | bash -
# yum -y install nodejs
Or
# dnf -y install nodejs

2. Yarn – Node.js Package Manager

Not only is Yarn a fast, secure, reliable, and open-source package manager but it is also a project manager for stable and reproducible projects. Yarn works everywhere: on Linux, Windows and macOS, and other UNIX-like operating systems that support Node.js.

As a package manager, it allows you to share your code through a package with other developers in the world over. In the same manner, you can also use code from other developers in your application.

Yarn supports workspaces for small, medium to large monorepo projects by enabling you to split your project into sub-components stored within a single repository. Another key feature of Yarn is the offline cache which allows it to work fine even when the network is down.

Yarn also ships with a modular API that can be extended through plugins. You can use official plugins or write your own. Plugins can be used to add new features, new resolvers, new linkers, new commands, register to some events, and can be integrated with each other. Additionally, it features a Plug’n’Play (PnP) API that allows you to introspect the dependency tree at runtime.

Furthermore, Yarn is also well documented and some of its features are still in incubation such as constraints, release workflow and “zero-install” which is more of a philosophy than a feature.

To install the latest version of Yarn on Linux systems, you need to first install Node.js on the system, and then install the Yarn using the following commands on your respective Linux distribution.

Installing Yarn on Debian and Ubuntu

$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt update
$ sudo apt install yarn

Installing Yarn on CentOS, RHEL, and Fedora

# curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
# rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
# yum install yarn
OR
# dnf install yarn

3. Pnpm – Node.js Package Manager

pnpm is a fast, disk-space efficient, and open-source package manager. It is cross-platform, it works on Linux, Windows, and macOS. Unlike npm and yarn which create flat node_modules directory, pnpm works a little differently: it creates a non-flat node_modules layout that uses symbolic links to create a nested structure of dependencies.

The files inside node_modules are linked from single content-addressable storage. This approach is efficient that it enables you to save gigabytes of disk space.

The non-flat node_modules approach also makes pnpm strict when it comes to dependency management, it allows a package to only access dependencies specified in its package.json file. It also has built-in support for workspaces meaning you can create a workspace to unite multiple projects inside a single repository.

Importantly, pnpm can easily be used in various CI applications such as Travis, Semaphore, AppVeypr, and Sail CI. And you can configure your project such that other users can only use pnpm but not the other Node.js package managers above, for example, when someone attempts to run “npm install” or “yarn install”.

pnpm also supports aliases that let you install packages with custom names, command-line tab completion, and uses a lock file called pnpm-lock.yaml.

The easiest way to install pnpm is by using npm package manager as shown.

Installing Pnpm on Debian and Ubuntu

$ sudo npm install -g pnpm

Installing Pnpm on CentOS, RHEL, and Fedora

# npm install -g pnpm

In this article, we have reviewed top Node.js package managers you can install in Linux. We would like to know your thoughts about this article, share them with us via the feedback form below.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.