Nvm: Npm hangs or is not installed through nvm

Created on 28 Aug 2018  路  6Comments  路  Source: nvm-sh/nvm

  • Operating system and version:
    macOS High Sierra version 10.13.6

  • nvm debug output:


$ nvm debug
nvm --version: v0.33.11
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/bash
$SHLVL: 1
$HOME: /Users/lwillmeth
$NVM_DIR: '$HOME/.nvm'
$PATH: $NVM_DIR/versions/node/v8.11.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)'
uname -a: 'Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64'
OS version: Mac 10.13.6 17G65
curl: /usr/bin/curl, curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0
wget: not found
git: /usr/bin/git, git version 2.15.2 (Apple Git-101.1)
grep: /usr/bin/grep, grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20070501
sed: illegal option -- -
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
sed: /usr/bin/sed, 
cut: illegal option -- -
usage: cut -b list [-n] [file ...]
       cut -c list [file ...]
       cut -f list [-s] [-d delim] [file ...]
cut: /usr/bin/cut, 
basename: illegal option -- -
usage: basename string [suffix]
       basename [-a] [-s suffix] string [...]
basename: /usr/bin/basename, 
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
rm: /bin/rm, 
mkdir: illegal option -- -
usage: mkdir [-pv] [-m mode] directory ...
mkdir: /bin/mkdir, 
xargs: illegal option -- -
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]
xargs: /usr/bin/xargs, 
nvm current: v8.11.4
which node: $NVM_DIR/versions/node/v8.11.4/bin/node
which iojs: 
which npm: $NVM_DIR/versions/node/v8.11.4/bin/npm
^C <- note, this command hangs and never finishes.

  • nvm ls output:

$ nvm ls
->      v8.11.4
         system
node -> stable (-> v8.11.4) (default)
stable -> 8.11 (-> v8.11.4) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.11.4)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.4 (-> N/A)
lts/carbon -> v8.11.4

  • How did you install nvm? (e.g. install script in readme, Homebrew):
    Install script in readme.

  • What steps did you perform?
    Installed nvm, $ nvm install --lts, then tried to run npm -v.

  • What happened?
    npm -v hangs, does not seem to be installed.

  • What did you expect to happen?
    I expected to see an npm version number.

  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?

Seemingly relevent segment of my ~/.bash_profile:

$ cat ~/.bash_profile 
export LOCAL_ENV=true
export NODE_ENV=development
export SKIP_BOT_MESSAGES=true
export NODE_LOGGER_CONSOLE=true
export NODE_LOGGER_CONSOLE_LEVEL=debug

export NVM_DIR="/Users/lwillmeth/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

proml
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

  • If you are having installation issues, or getting "N/A", what does curl -I --compressed -v https://nodejs.org/dist/ print out?

$ curl -I --compressed -v https://nodejs.org/dist/
*   Trying 104.20.23.46...
* TCP_NODELAY set
* Connected to nodejs.org (104.20.23.46) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-CHACHA20-POLY1305
* ALPN, server accepted to use h2
* Server certificate:
*  subject: OU=Domain Control Validated; OU=PositiveSSL Wildcard; CN=*.nodejs.org
*  start date: Aug 14 00:00:00 2017 GMT
*  expire date: Nov 20 23:59:59 2019 GMT
*  subjectAltName: host "nodejs.org" matched cert's "nodejs.org"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fcd48805e00)
> HEAD /dist/ HTTP/2
> Host: nodejs.org
> User-Agent: curl/7.54.0
> Accept: */*
> Accept-Encoding: deflate, gzip
> 
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200 
HTTP/2 200 
< date: Tue, 28 Aug 2018 20:43:10 GMT
date: Tue, 28 Aug 2018 20:43:10 GMT
< content-type: text/html
content-type: text/html
< set-cookie: __cfduid=d7dd58874f6a6d69db1f7ddc5aafb25b41535488990; expires=Wed, 28-Aug-19 20:43:10 GMT; path=/; domain=.nodejs.org; HttpOnly
set-cookie: __cfduid=d7dd58874f6a6d69db1f7ddc5aafb25b41535488990; expires=Wed, 28-Aug-19 20:43:10 GMT; path=/; domain=.nodejs.org; HttpOnly
< cf-cache-status: HIT
cf-cache-status: HIT
< vary: Accept-Encoding
vary: Accept-Encoding
< expires: Wed, 29 Aug 2018 00:43:10 GMT
expires: Wed, 29 Aug 2018 00:43:10 GMT
< cache-control: public, max-age=14400
cache-control: public, max-age=14400
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< server: cloudflare
server: cloudflare
< cf-ray: 45199bd17dc62a73-SEA
cf-ray: 45199bd17dc62a73-SEA
< content-encoding: gzip
content-encoding: gzip

< 
* Connection #0 to host nodejs.org left intact

Basically, I can't seem to use npm through nvm. Node seems to install but npm doesn't. Any ideas?

$ which node
/Users/lwillmeth/.nvm/versions/node/v8.11.4/bin/node

$ which npm
/Users/lwillmeth/.nvm/versions/node/v8.11.4/bin/npm

$ npm -v
^C <- hangs, has to be cancelled.

Most helpful comment

I tried to reinstall nvm from the shell script, but it hung too. So I downloaded the script and ran it locally. That hung. So I cloned the git repo and tried to check out the v0.33.11 branch.

On each step, I found it less and less likely that the problem was with nvm itself. When git checkout v0.33.11 hung, I knew it must be on my end. It turns out my antivirus started silently failing terminal commands. As soon as I whitelisted the ~/.nvm directory nvm works perfectly.

Thank you @ljharb for your quick and reasonable responses, and sorry for wasting your time!

All 6 comments

I realized that nvm install v6.9.1 hangs, which could explain why npm doesn't seem to be fully installed? I started the command, tabbed away and 20 minutes later this is what I see:

$ nvm install v6.9.1
Downloading and installing node v6.9.1...
Downloading https://nodejs.org/dist/v6.9.1/node-v6.9.1-darwin-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!

Note that it has not returned to a prompt yet, the program is still running. I assume this isn't normal/expected behavior?

Nvm seems to hang on a lot of commands:

$ nvm ls
->       v6.9.1
        v8.11.4
node -> stable (-> v8.11.4) (default)
stable -> 8.11 (-> v8.11.4) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.11.4)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.4 (-> N/A)
lts/carbon -> v8.11.4

$ nvm use v8.11.4
<never finishes or returns anything>
^C

$ nvm ls
         v6.9.1
->      v8.11.4
node -> stable (-> v8.11.4) (default)
stable -> 8.11 (-> v8.11.4) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.11.4)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.4 (-> N/A)
lts/carbon -> v8.11.4

Is it normal for commands like that to hang? Should I uninstall/reinstall nvm?

It's definitely not normal; but I doubt reinstalling nvm will fix it.

What happens if you run set -x; nvm install 6.9.1? (the output will be long)

I tried reinstalling nvm and noticed something odd. The directions said to delete ~/.nvm so I did, but afterwards.. nvm still runs.

$ ls ~/.nvm
ls: /Users/lwillmeth/.nvm: No such file or directory

$ which nvm

$ nvm ls
            N/A
node -> stable (-> N/A) (default)
iojs -> N/A (default)

$ ls ~/.nvm/
alias

So nvm is installed somewhere, and for some reason running it makes an (empty) directory called ~/.nvm/alias/lts/

I'm not sure how else to remove nvm, or where it could be installed. I've never seen which nvm fail to return an answer before. I'm puzzled.

I think my best bet is to find and remove this phantom install, get nvm reinstalled normally, and try again. Any ideas on where else it could be hiding?

nvm is a sourced shell function, so deleting $NVM_DIR isn't sufficient - you'd also have to close and reopen your terminal.

I tried to reinstall nvm from the shell script, but it hung too. So I downloaded the script and ran it locally. That hung. So I cloned the git repo and tried to check out the v0.33.11 branch.

On each step, I found it less and less likely that the problem was with nvm itself. When git checkout v0.33.11 hung, I knew it must be on my end. It turns out my antivirus started silently failing terminal commands. As soon as I whitelisted the ~/.nvm directory nvm works perfectly.

Thank you @ljharb for your quick and reasonable responses, and sorry for wasting your time!

Was this page helpful?
0 / 5 - 0 ratings