I have installed Ubuntu Bash on Windows. I already have nodejs
and npm
on my windows machine at C:\\Program Files\\nodejs
. In the bash she
Note: Before following the steps below, first try to restart your shell.
You can install node and npm with your Windows PowerShell as well, so if you've done that it won't work properly for your Subsystem. That means you have to install it twice (Powershell and Subsystem), decide for one thing, or adjust the environment variables.
If the preceding text, has not helped you, this is how to solve the problem:
Remove your current installations
sudo apt-get --purge remove node
("sudo apt autoremove node" if console is asking for)
sudo apt-get --purge remove nodejs
Install node the right way. This is for version 10:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt install node
Then install build tools so you can install add-ons for npm later
sudo apt-get install -y build-essential
Now you can type in
npm -v
node -v
Same thing: nodejs -v
to check whether npm is installed correctly. If it shows nothing, restart the shell.
Here is a link that may help you.
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
this is enough, if you still face the problem
node installation needs restart, close you ubuntu window and start again it will solve your problem :)
I received this error when I modified my "~/.bashrc" file to shorten up the bash directory.
At first I had:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\$'
fi
....But then could not run any node operation. I rolled it back and the error stopped happening.
After some troubleshooting, I was able to fix the error by adding ~
before the $
on PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\~$
I had the same problem to solve I installed "NVM" in my Subsystem
Follow these steps and see if it will solve for you:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile
nvm install 11.13.0
I had the same problem. This is what I did.
Step 1. Type node -v
and npm -v
commands in Windows PowerShell and check if node and npm are properly installed
Step 2. Add this to the ~/.zshrc
or ~/.bashrc
file
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"
Step 3. type source ~/.zshrc
and/or source ~/.bashrc
Step 4. Type node -v
and npm -v
commands in bash
or zsh
shells and the correct versions should now appear
Hope this solves your problem. Peace! ✌
I had the same error and it may seem silly, but I fixed it by simply typing exit
in the console and opening it again.