Install yarn and npm in WSL
Solution 1
Look at this:
/mnt/c/Users/chengtie/AppData/Roaming/npm/yarn: 12
It is looking for the yarn installed on Windows. You must or uninstall yarn from windows or remove it from the WSL's PATH.
Use the following to remove windows yarn from the PATH:
WIN_YARN_PATH="\$(dirname "\$(which yarn)")"
export PATH=\$(echo "\${PATH}" | sed -e "s#\${WIN_YARN_PATH}##")
You can add this to your .bashrc
Also, look at your error messages it is getting also npm from windows, you need to remove them from the path using the same technique.
Solution 2
You need to type:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
then:
sudo apt-get install -y nodejs
Solution 3
You must install nodejs before
sudo apt-get install nodejs
Solution 4
If you have latest nodejs version installed:
I encountered the same issue and it got fixed by trying sudo npm -v
and to get npm without sudo, I restarted the WSL.
If you don't have the latest nodejs version:
If you are on WSL, you can install the Latest stable version by
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
In place of setup_8.x
you can keep setup_16.x
for version 16 (which includes npm).
sudo apt-get install nodejs
check nodejs version by nodejs -v
.
check npm version by npm -v
.
If still the same error codes. try sudo npm -v
or restart PC/ WSL then try npm -v
.
SoftTimur
Updated on June 06, 2022Comments
-
SoftTimur almost 2 years
I have installed Windows Subsystem for Linux (WSL) and Ubuntu 16.04 on my Windows 10. Then I followed this to install yarn:
sudo apt update sudo apt install curl curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt update sudo apt install yarn
It did not raise any error. However,
yarn --version
returned$ yarn --version /mnt/c/Users/chengtie/AppData/Roaming/npm/yarn: 12: /mnt/c/Users/chengtie/AppData/Roaming/npm/yarn: node: not found
npm --version
returned$ npm --version : not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm: : not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm: /mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")
Does anyone know how to fix this?
-
SoftTimur about 4 yearsI did.
nodejs --version
returnedv4.2.6
. -
CharlesRA about 4 years@SoftTimur Maybe you could try install yarn with
sudo npm install -g yarn
-
SoftTimur about 4 years
sudo npm install -g yarn
returnedsudo: npm: command not found
. -
CharlesRA about 4 yearsWell two possibilies, you can install npm with
sudo apt-get install npm
or you can make sure your env variable $PATH is linked with you linux bin directories -
SoftTimur about 4 yearsIndeed, I need to do both:
sudo apt-get install npm
, and remove npm and nodejs in Windows from$PATH