Last Updated on: March 30, 2023 by Heyan Maurya
PNPM is an efficient alternative to NPM and Yarn package managers for Node.js packages, which works differently than them to manage modules. In this article, we learn how to install PNPM on Ubuntu 22.04 or 20.04 Linux systems.
What is the PNPM Nodejs, package manager?
PNPM stands for “Performant npm” and it aims to improve the performance and disk space usage of traditional Nodejs package managers by using shared content-addressable storage for package files across projects. In other words, instead of installing multiple copies of the same package in different projects, PNPM stores a single copy of each version of a package on the file system and then links it to the different projects that require it.
This approach can lead to significant disk space savings and faster installation times, especially when working with large projects or multiple projects that depend on the same packages. Furthermore, the PNPM Node.js package manager to prevent version conflicts has a centralized lock file to support multiple package versions installed at the same time. PNPM also creates non-flat node_modules by default, so the code has no access to arbitrary packages.
Hence, PNPM is worth trying if you are NodejS developers who want a fast and efficient package manager that can handle large-scale projects with multiple dependencies.
On the Page hide
PNPM Nodejs pacakge manager installation in Ubuntu
1. Start with a system update
2. Add NodeJS Repository
3. Install NodeJS
3. Install PNPM on Ubuntu 22.04 or 20.04 for NodeJS
4. Check PNPM Version
5. Examples of PNPM commands
Install packages:
Install packages as development dependencies:
Install packages globally:
Uninstall pnpm packages:
Update pnpm packages:
Install packages from a lockfile:
List installed pnpm packages:
Search for packages:
Run a script defined in package.json:
Clean pnpm cache:
6. Update to latest
7. Uninstall PNPM
The commands given here are not just limited to Ubuntu 22.04 or 20.04 Linux instead the newer versions of the OS including Debian, Linux Mint, POP Os, MX Linux, and similar distro users can follow them.
Use the Ubuntu command terminal, if you are not a CLI server user then you can run the terminal app using Ctrl+ALT+T or from the Application menu by searching for it.
sudo apt update
Also, install CURL:
sudo apt install curl -y
If your Ubuntu system already has Nodejs installed then you can move to next for the PNPM installation, however, for those who don’t have it, go for the given commands.
Although we already have the node.js to install on Ubuntu using its default base repo, however, the version will be old. Hence, those who want to get the latest and current version of Node need to add the official Node.js repository manually on Ubuntu Linux.
There are two types of Nodejs releases one is current and the other long-term supported. As per your choice go for the given repository.
Note: Use only one of them.
For the latest current version:
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
For LTS- Long Term Supported version use this repo instead above one:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
Here to perform this tutorial we are using the LTS version of NodeJS.
After adding the repository, we can use the default system package manager that is APT to install the current or LTS version of Nodejs Javascript.
sudo apt-get install -y nodejs
The next task of our to complete this tutorial is to install PNPM on Ubuntu Linux. We already have NodeJS along with NPM but if you don’t want to use NPM to manage libraries and modules for your Nodejs project then simply use the given command. It uses CURL to fetch the official script made by the developers of the PNPM package manager to easily install it on Linux distros.
curl -fsSL https://get.pnpm.io/install.sh | sh -
Wait for a few seconds and the PNMP will be on your system. Once the process is done, source your bashrc file so that the system can recognize the path added to it by the above command.
source ~/.bashrc
Now, let’s confirm this NodeJs package manager is on our Ubuntu Linux system and working fine, check its version.
pnpm --version
Also, further, just like NPM, we can use it to install packages, for example:
pnpm add curl
Here are some examples of command syntax that can be used to work with the PNPM package manager for Nodejs projects.
Note: Replace
pnpm add
pnpm add --save-dev
pnpm add -g
pnpm uninstall
pnpm update
pnpm install --frozen-lockfile
pnpm ls
pnpm search
pnpm run
pnpm store prune
These are just a few examples of PNPM commands. For more commands and their detailed information visit the official documentation.
To upgrade the PNPM to its latest available version, simply run the same script you have used to install it.
curl -fsSL https://get.pnpm.io/install.sh | sh -
Well, there might be chances that you still prefer NPM over PNPM, then you surely want to remove PNPM from your Ubuntu Linux, if that is so, here is the command to follow:
Remove its folder
rm -r ~/.local/share/pnpm
If you also want to remove the modules or libraries installed by PNPM then run:
rm -r ~/node_modules
To remove it from your system path, edit the Bashrc file and remove the following code.
nano ~/bashrc
Scroll down and find the given line. Delete it and save the file using Ctrl+X, pressing Y to confirm, and then hit Enter key to exit.
# pnpm
export PNPM_HOME="/home/h2s/.local/share/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
# pnpm end
Other Articles:
Refer link: How to install PNPM on Ubuntu 22.04 or 20.04