skip to Main Content

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


  1. You must install nodejs before

    sudo apt-get install nodejs
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. You need to type:

    curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
    

    then:

    sudo apt-get install -y nodejs
    
    Login or Signup to reply.
  5. if you already has NodeJS v16.10 or higher, then

    corepack enable 
    

    otherwise you can install corepack beforehand

    https://yarnpkg.com/getting-started/install

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search