fnm icon indicating copy to clipboard operation
fnm copied to clipboard

how to have sudo ?

Open GrosSacASac opened this issue 3 years ago • 0 comments

sudo: npm: command not found

GrosSacASac avatar Jul 26 '22 17:07 GrosSacASac

this is a permissions thing. I don't assume anything about your setup but I guess the following should work:

sudo "$(which fnm)" exec --using="$(fnm current)" npm --version

let's break it down:

  1. sudo calling sudo 👉😎👉
  2. "$(which fnm)" expands into "/Users/schniz/Code/fnm/target/debug/fnm" on my machine, but I guess that on your machine it will expand to the location of the fnm binary
  3. exec - run fnm and add the PATH information needed to the next command (see fnm exec --help)
  4. --using="$(fnm current)" will expand into your current version of Node.js: --using="16.0.0" if you're using Node.js v16.0.0
  5. npm --version will be the command to run

Since this obnoxiously explicit command is working, it seems like it isn't an fnm question but more of a specific shell configuration issue so I'm closing it.

If you have any suggestion on how to make it easier I'm all ears :pray: thank you for your contribution :pray:

Schniz avatar Aug 16 '22 12:08 Schniz