skip to Main Content

I’m running Ubuntu via WSL. I originally had the bash shell running but switched to zsh. Node.js was installed on bash and was up to date. I tried to npm install on a project and noticed that node wasn’t installed for zsh. So, I went to install node on zsh but it was never installing the latest version of node and whenever I tried running npm, I would get zsh: command not found: npm.

I’ve tried uninstalling node from zsh and reinstalling but it still installs an older version of node for some reason and without npm. I used sudo apt install nodejs and tried sudo apt install npm. Nothing changed.

2

Answers


  1. Chosen as BEST ANSWER

    Found the issue. When Oh My ZSH was installed, the path to the installed node and nvm files from bash was not linked for some reason. I had to add export PATH=/home/MYUSERNAME/.nvm/versions/node/v18.14.1/bin:$PATH to the top of the zshrc file. Added it directly below the top commented line that says "If you come from bash you might have to change your $PATH. I also commented out the old PATH just in case I needed it for some reason in the future.

    The zshrc file can be accessed for editing using nano ~/.zshrc.

    Your current zsh file path can be found using echo $PATH To change the shell back to bash to get your path use chsh -s /bin/bash Use echo $PATH in bash and locate the path for your node (mine was at the start of the path). Copy this small section of the full path to use for your zshrc file.

    Switch back to zsh using chsh -s /bin/zsh.

    The current terminal you are using can be found using echo $0


  2. usually, by default it will use bash

    to import all available command from bash, you can do:

    open ~/.zshrc using any editor, and put this in the beginning of ~/.zshrc

    source /home/YOUUSERNAME/.bash_profile
    

    and if you only need to add node, do this in your bash

    'export NODE_PATH=~/local/:~/local/node_modules' >> ~/.zshrc
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search