ZSH npm/node/nvm command not found after installing OhMyZSH

41,143

Solution 1

Added this line to ./zshrc file. Working great. Original source: https://github.com/lukechilds/zsh-nvm

export NVM_DIR=~/.nvm
 [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

Solution 2

Adding plugin nvm, just edit .zshrc file

plugins=(git nvm)

Close terminal, reopen terminal, hope this solves the problem on your machine too.

Found this solution from this blog post https://www.brijumaquio.com/node-not-working-after-installing-zsh-ubuntu18

Solution 3

I faced the same issue. Details in Gist.

  1. Installed nodeJs via nvm using Git Bash
  2. Installed hyper terminal & WSL
  3. Installed Ubuntu (windows Store) & configured zsh shell. 
  4. Faced the command not found all over in the zsh shell
  5. The same commands are working nicely in the bash shell

Tried sourcing the (node, nvm, npm ) paths in the .zshrc and .profile file & modified the System & Environment Variables in Windows. None of these steps helped me to resolve the issue.

I think the issue is zsh and bash terminals treat things differently. When Installed in bash terminal the default location for the nodeJs in windows will be set to

C:\Users\Program Files\nodejs

The above one is symlinked to C:\Users\<username>\AppData\Roaming\nvm

No matter how much I tried to alias these things in zsh, only node and nvm are working with aliases. npm is failing to locate the necessary lib files.

The only solution that worked for me is Re-installing node in zsh terminal

  1. Removed the node versions installed via nvm in Bash terminal.
  2. Removed the nvm in windows via control Panel
  3. Installed the nvm in the zsh shell
  4. Installed the node latest LTS version from which npm is also installed.

Post Installing the node via nvm in Zsh I observed the following things.

  1. Paths for the node, nvm, npm & npx have been automatically added to the $PATH variable
  2. Node directory is not available neither in C:\Users\Program Files\nodejs nor the C:\Users\{username}\AppData\Roaming\nvm
  3. Instead it is configured differently at /home/<username>/.nvm/versions/node/v14.15.1/bin/node

This video really helped me in re-installing the node in ZSH: https://www.youtube.com/watch?v=kL8iGErULiw

Share:
41,143

Related videos on Youtube

Verthon
Author by

Verthon

Updated on September 18, 2022

Comments

  • Verthon
    Verthon over 1 year

    After installing OhMyZSH on my Linux machine, previously installed nvm, node and npm are not found. Thanks for the help.

    This command "source ~/.nvm/nvm.sh" allows me to make it work, however when I restart terminal or open new tab terminal says that commands are not found... Config '~/.zshrc' file:

    # If you come from bash you might have to change your $PATH.
     export PATH=$HOME/bin:/usr/local/bin:$PATH
    
    # Path to your oh-my-zsh installation.
     export ZSH="/home/jurr/.oh-my-zsh"
    
  • C13L0
    C13L0 over 3 years
    This solution worked perfect for macOS Big Sur
  • Nishant Mendiratta
    Nishant Mendiratta about 2 years
    This one works man!!!!!! Thank you so much