How to fix "command not found" for global pnpm packages

This article was published on Nov 16, 2021, and takes approximately a minute to read.

I've slowly started to replace Yarn/npm with pnpm whenever I can.

Despite using it in projects (which is not always that easy), I've decided to start using it for global packages (where I have some control).

However, like npm or Yarn, it doesn't work out-of-the-box when you're using a particular node installation like I use asdf to control my runtime versions.

For installing global packages, it's the same as we know:

pnpm add --global live-server

This should invoke the binary automatically, but instead, I got:

zsh: command not found: live-server

I remember I had this problem before with npm, and the solution was adding in my PATH the location npm's binaries.

To know that, pnpm give us a command pnpm bin --global:

~ » pnpm bin --global
/Users/raulmelo/.asdf/plugins/nodejs/shims

So all I needed was to concatenate the result of this command in whatever my $PATH already is in my ~/.zshrc configuration:

export PATH=$(pnpm bin --global):$PATH

Then, after reloading my terminal session with source ~/.zshrc or opening another tab, I can call all binaries installed via pnpm.

Obs.: this also works for NPM; you only have to replace the pnpm command with $(npm bin -g).

Resources