0

I'm struggling to understand how exactly WSL works.

The training that I'm doing requires nvm so I can manage my node versions in my project, located in my hard drive that is running with Windows.

So, in order to use nvm I need WSL, but I cannot comprehend where it is located. As far as I understood (and I'm pretty sure that I'm wrong) the WSL that I installed is like a Linux VM, completely independent from my Windows, and I operate it through the Ubuntu Terminal that came with WSL. If that's the case, how can nvm in WSL be useful if my project is in my Windows directory and the WSL controls node versions from my Linux VM?

How do I make nvm useful for my project running from my C:\ drive and how does WSL work with nvm in my Windows?

Thank you!

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
  • Are you using WSL1 or WSL2? – Dai Oct 17 '22 at 03:11
  • 1
    nvm is the tool for you to manage Node.js installation on a machine (in your case, Windows). Why do you need WSL here? So far, this question makes no sense to me. WSL is a virtualized Linux environment mostly separated from Windows (with some integration), so you don't need to learn/use it if Windows is all you wanted. – Lex Li Oct 17 '22 at 03:36
  • Sorry, I'm new in this, and the only way I could find to install nvm was through WSL. I installed WSL using "wsl --install --online Ubuntu", and I don't know if this WSL 1 or 2. So, I assume that what I said was correct, except for the part that I was using WSL to install nvm. Is there a way to install nvm in my windows without WSL? Thank you. – gio broliatto Oct 17 '22 at 16:26

1 Answers1

0

A few options, but each has advantages and disadvantages:

  • If your Node/JavaScript files are on your Windows C:\ drive, then you do have the ability to access that from WSL. Windows paths are automatically mounted and accessible in WSL via /mnt/c, /mnt/d, etc.

    So if you have your JS source in, for example:

    C:\Users\<myusername>\Documents\Projects\JS_class\project1\
    

    Then that would be accessible under Ubuntu in WSL via:

    /mnt/Users/<myusername>/Documents/Projects/JS_class/project1/
    

    The disadvantage here is performance, as mentioned in this question.

  • Alternatively, you can store your project files inside WSL. You can access the WSL path from Windows by using \\wsl$\Ubuntu\home\<yourusername>\ (or similar). You can use this to copy from your existing Windows drive to your WSL distribution.

    Advantage: Faster. Disadvantage: Unknown -- You seem to want the files to be in Windows, but I'm not sure why.

  • Or you can use WSL1 for most Node/JS tasks. See the previously mentioned answer for details on how to convert.

    Advantage: Speed

    Disadvantage: WSL1 hasn't been updated in a while, and is started to run into some compatibility issues. It's still popular enough and stable enough at the moment for me to continue to recommend it, though.

  • There's also a Windows version of nvm as well as a replacement project that the repo there mentions. I cannot personally speak for the quality of it, but it does have 23k stars on Github. Note that it is not affiliated with the original (Linux-based) nvm project.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70