nvm: NPM global packages not found - fix
Globally installed modules were not found in the path. I did not want to manually alter the path in my bashrc because running “nvm use” would not change the path accordingly. Searching online, there are many “hacks”, but I found a very simple fix. It works great for me, but I will lose the change if I upgrade or reinstall. Is this something that should or could be added?
In “nvm.sh”, search for “# Change current version”. There is a line that updates the path (first line below). I added the 2nd line below and it all worked great.
PATH="$(nvm_change_path "${PATH}" "/bin" "${NVM_VERSION_DIR}")"
PATH="$(nvm_change_path "${PATH}" "/lib/node_modules" "${NVM_VERSION_DIR}")"
Operating system and version:
nvm debug
output:
NOTE: Path abbreviated. I removed the WSL/Windows items.
nvm --version: v0.38.0
$SHELL: /bin/bash
$SHLVL: 1
whoami: 'edobrzel'
${HOME}: /home/edobrzel
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ./node_modules/.bin:${NVM_DIR}/versions/node/v16.10.0/lib/node_modules:${NVM_DIR}/versions/node/v16.10.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)'
uname -a: 'Linux 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux'
checksum binary: 'sha256sum'
OS version: Ubuntu 20.04 LTS
curl: /usr/bin/curl, curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
wget: /usr/bin/wget, GNU Wget 1.20.3 built on linux-gnu.
git: /usr/bin/git, git version 2.25.1
grep: /usr/bin/grep (grep --color=auto), grep (GNU grep) 3.4
awk: /usr/bin/awk, GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)
sed: /usr/bin/sed, sed (GNU sed) 4.7
cut: /usr/bin/cut, cut (GNU coreutils) 8.30
basename: /usr/bin/basename, basename (GNU coreutils) 8.30
rm: /usr/bin/rm, rm (GNU coreutils) 8.30
mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.30
xargs: /usr/bin/xargs, xargs (GNU findutils) 4.7.0
nvm current: v16.10.0
which node: ${NVM_DIR}/versions/node/v16.10.0/bin/node
which iojs:
which npm: ${NVM_DIR}/versions/node/v16.10.0/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v16.10.0
npm root -g: ${NVM_DIR}/versions/node/v16.10.0/lib/node_modules
nvm ls
output:
-> v16.10.0
default -> node (-> v16.10.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.10.0) (default)
stable -> 16.10 (-> v16.10.0) (default)
lts/* -> lts/fermium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.6 (-> N/A)
lts/fermium -> v14.18.0 (-> N/A)
How did you install nvm
?
curl
What steps did you perform?
npm i rimraf -g
rimraf ../someFolder
What happened?
Global module “rimraf” was not found.
What did you expect to happen?
I expected global modules to work.
Is there anything in any of your profile files that modifies the PATH
?
Append-only in bashrc.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 19 (8 by maintainers)
Oh boy, I figure it out. I misspelled the package name during install. So it installed another package that has not the command I was running.
My bad.
Oh jeez I was installing the wrong package… Nevermind.