nvm: NVM command not found after terminal restart.

I’ve used NVM for the past two years successfully. However, after setting up a new dev environment on a new laptop I can’t get NVM to persist. I install via curl, execute the export command, and nvm works until I close terminal. Once I reopen terminal I get zsh: command not found: nvm whenever I try to use nvm.

Operating system and version:

MacOS Catalina 10.15.5

nvm debug output:

nvm --version: v0.36.0
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/zsh
$SHLVL: 1
whoami: 'tyleryoungblood'
${HOME}: /Users/tyleryoungblood
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${NVM_DIR}/versions/node/v8.9.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: 'zsh 5.7.1 (x86_64-apple-darwin19.0)'
uname -a: 'Darwin 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64'
checksum binary: 'shasum'
OS version: Mac 10.15.5 19F101
curl: /usr/bin/curl, curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2
wget: not found
sed: /usr/bin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir
xargs: /usr/bin/xargs
git: /usr/local/bin/git, git version 2.28.0
grep: /usr/bin/grep, grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20070501
nvm current: v8.9.4
which node: ${NVM_DIR}/versions/node/v8.9.4/bin/node
which iojs: iojs not found
which npm: ${NVM_DIR}/versions/node/v8.9.4/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v8.9.4
npm root -g: ${NVM_DIR}/versions/node/v8.9.4/lib/node_modules

nvm ls output:

->       v8.9.4
         system
default -> 8.9.4 (-> v8.9.4)
node -> stable (-> v8.9.4) (default)
stable -> 8.9 (-> v8.9.4) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> 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.22.0 (-> N/A)
lts/erbium -> v12.18.3 (-> N/A)

How did you install nvm?

via curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash

What steps did you perform?

After installing nvm via the curl command listed above (and executing the export command), everything works properly until I restart terminal.

What happened?

Nvm does not persist after terminal restart.

What did you expect to happen?

Nvm to continue to work after terminal restart. If I try to reinstall via curl, it says it’s already installed. All I have to do is rerun the export command to get things working again.

Is there anything in any of your profile files that modifies the PATH?

Yes, I’ve pasted the details of my .bash_profile and .bashrc below.

.bash_profile

alias terminus=~/vendor/bin/terminus
export PATH="$HOME/.composer/vendor/bin:$PATH"

source ~/.bashrc

.bashrc

alias terminus=~/vendor/bin/terminus
export PATH="$HOME/.composer/vendor/bin:$PATH"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"
NPM_PACKAGES=/Users/tyleryoungblood/.npm-packages


export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -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?

*   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
* 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, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (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: Oct 21 00:00:00 2019 GMT
*  expire date: Jan 18 23:59:59 2022 GMT
*  subjectAltName: host "nodejs.org" matched cert's "nodejs.org"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=Sectigo Limited; CN=Sectigo 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 0x7fa04400b400)
> HEAD /dist/ HTTP/2
> Host: nodejs.org
> User-Agent: curl/7.64.1
> Accept: */*
> Accept-Encoding: deflate, gzip
> 
* Connection state changed (MAX_CONCURRENT_STREAMS == 256)!
< HTTP/2 200 
HTTP/2 200 
< date: Tue, 29 Sep 2020 23:50:33 GMT
date: Tue, 29 Sep 2020 23:50:33 GMT
< content-type: text/html
content-type: text/html
< set-cookie: __cfduid=d9827a78b3349ac35c4fe1cbcca5ab43d1601423433; expires=Thu, 29-Oct-20 23:50:33 GMT; path=/; domain=.nodejs.org; HttpOnly; SameSite=Lax
set-cookie: __cfduid=d9827a78b3349ac35c4fe1cbcca5ab43d1601423433; expires=Thu, 29-Oct-20 23:50:33 GMT; path=/; domain=.nodejs.org; HttpOnly; SameSite=Lax
< cache-control: max-age=14400
cache-control: max-age=14400
< cf-cache-status: HIT
cf-cache-status: HIT
< age: 11680
age: 11680
< cf-request-id: 057ddf78ce0000ba0a13318200000001
cf-request-id: 057ddf78ce0000ba0a13318200000001
< 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"
< vary: Accept-Encoding
vary: Accept-Encoding
< server: cloudflare
server: cloudflare
< cf-ray: 5da99b6e19c9ba0a-ATL
cf-ray: 5da99b6e19c9ba0a-ATL
< content-encoding: gzip
content-encoding: gzip

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 32 (11 by maintainers)

Most upvoted comments

I am still facing the issue pls help?

run source ~/.nvm/nvm.sh and if it doesn’t work after you close and open the terminal you need to create the zsh with nano or vim or whatever you are comfortable with and paste the code above inside, save the file, close the terminal then start the terminal.

e.g nano ~/.zshrc then paste the code source ~/.nvm/nvm.sh then cmd + V then ctrl+X then hit enter /return key then close the terminal and start it again, you should be fine

add export NVM_DIR=“$([ -z “${XDG_CONFIG_HOME-}” ] && printf %s “${HOME}/.nvm” || printf %s “${XDG_CONFIG_HOME}/nvm”)” [ -s “$NVM_DIR/nvm.sh” ] && . “$NVM_DIR/nvm.sh” # This loads nvm to .zprofile if you

Would curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash have to be changed to curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | $SHELL in order for the proper shell to be detected?

This line looks like it would detect a Bash version if the script is being piped into Bash, regardless of what the user’s default shell is.

I’m having the same issue. I have to run on each new session :

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" in each ne

Catalina uses zsh by default. Do you have any nvm lines in .zshrc or .zprofile?

@smellyd note that the sourcing lines are a bit longer than that - see the readme. However, this suggests that your shell isn’t sourcing .zshrc at all. You may need .zprofile?

thanks ljharb, succesfull .zprofile

@smellyd note that the sourcing lines are a bit longer than that - see the readme. However, this suggests that your shell isn’t sourcing .zshrc at all. You may need .zprofile?

@ljharb Thanks. I am new and I thought .zshrc would have all of the global stuff in it. I created a .zprofile and added export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" and that did the trick.

@elhamhashemii the node version has no bearing on it. Please file a new issue and fill out the entire issue template, and I’ll be able to help you.

Hi. Thanks for your reply. I just uninstalled my node completely and tried installing nvm again, and finally it worked. 🤩🥳

@elhamhashemii the node version has no bearing on it. Please file a new issue and fill out the entire issue template, and I’ll be able to help you.

@tyleryoungblood yes, either that or a .zprofile file. Those files have to exist for the install script to modify them - so theoretically you could also just touch the files, and see if the install script can add the lines into them for you?