How to install pnpm in Ubuntu

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to install pnpm in Ubuntu.

pnpm is a package manager that aims to be faster than the npm package manager.

pnpm like npm can also be installed and used in any Linux distro, including Windows and MacOS.

pnpm provides an installation script that you can download in your machine, and then use it to install pnpm in your system. Though this is not the only way to install pnpm.

pnpm can also be installed via corepack, the tool that Node.js is shipped with.

In this tutorial, we'll install pnpm in Ubuntu 22.04 via the official installation script , and via corepack.

Install pnpm in Ubuntu 22.04 via official installation script

The installation script of pnpm is a bash script that allows you to install pnpm in your Ubuntu system.

Step 1 - Update your system

Before you install pnpm in your system, make sure that package index in your Ubuntu system is updated.

sudo apt update

Step 2 - Install pnpm

Once you have updated your Ubuntu machine, you can proceed to install pnpm by using the official installation script.

To do so, simply run the command below.

curl -fsSL https://get.pnpm.io/install.sh | sh -

💡
Note: The command above will download pnpm installation script install.sh from the offficial pnpm domain, and execute it once downloaded.

1) If you want to inspect the installation script before installing it, simply download the installation script via wget or curl.

wget https://get.pnpm.io/install.sh

2) Then to install pnpm, you need to make the installation script executable first.

chmod +x install.sh

3) Install pnpm

Now simply issue the following to run the pnpm installer and install pnpm.

./install.sh

Step 3 - Add pnpm to PATH

To be able to run pnpm in your terminal, you need to add it to your PATH.

Adding pnpm to your PATH variable is quite simple, and it can be done by running the command below.

source ~/.bashrc

Step 4 - Verify pnpm installation

pnpm should be now installed in your machine.

Before you start using pnpm, verify first that pnpm is working.

pnpm --version

The command above should show the version of pnpm, which means pnpm should be working if you see a similar output.

Install pnpm via corepack

corepack allows you to install pnpm package manager without having to download the installation script manually.

To install pnpm via corepack, you must have Node.js installed in your machine.

1) First enable corepack

corepack must be enabled in your system in order to install pnpm.

To enable corepack, simply run the following.

sudo corepack enable

2) Install pnpm

Once corepack is enabled, proceed to install pnpm.

corepack prepare pnpm@latest --activate
💡
Note: The command above will download the latest version of pnpm.

Conclusion

In this tutorial, you learned how to install pnpm package manager in Ubuntu 22.04, via two different ways, by using the official installation script of pnpm, and by using the corepack tool that Node.js is shipped with.