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?
5
Answers
You must install nodejs before
Look at this:
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:
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.
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 keepsetup_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 trynpm -v
.You need to type:
then:
if you already has NodeJS v16.10 or higher, then
otherwise you can install corepack beforehand
https://yarnpkg.com/getting-started/install