Install npm (Node.js Package Manager) on Windows (w/o using Node.js MSI)

前端 未结 11 2030
孤独总比滥情好
孤独总比滥情好 2020-12-23 12:53

The problem: while using nvm to install Node.js I was able to install the version of Node.js I need, but nvm does not install npm auto

11条回答
  •  盖世英雄少女心
    2020-12-23 13:18

    TL;DR: Install Chocolatey, Node (and NPM)

    Install Chocolatey

    NOTE: You might want to copy the exact command from their install page since it might change over time.

    1. Open your standard Windows command line
    2. @powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET PATH="%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
    3. Restart console
    4. Done!

    Install Node (and NPM)

    1. Because Chocolatey installs a directory different from the MSI installation, go to your system configuration and delete your previous node installation (if you have one)
    2. Install Chocolatey as described above
    3. choco install nodejs

      NOTE I used nodejs. I am not even sure what node is, but having had my fair share of troubles with node already being taken by something else in other systems, I thought, nodejs would be the safer bet right away

    4. Restart your console
    5. Beware: node -v works!
      • And npm -v also works! Awesome.

    After this, I was able to install firebase-tools without problems (which I was not able to do previously), so something must have gone terribly right! :)

    My rather complete story the first time around

    "Chocolatey installs in seconds"

    If you don't care about sarcasm or lamenting engineers on a Sunday afternoon, skip ahead to the installation instructions in the TL;DR section below.

    For everyone else: I want to amend this answer which recommends using (what seems to be the hottest package management solution for Windows right now): Chocolatey

    It gets the job done nice and quick. However, when I gave it a first try, it took me a while to make sense of the install instructions which are kinda convoluted. The install instructions go a bit like this (complete with what went through my head while going through it):

    • NOTE:
    • NOTE:
    • NOTE:

      three big-ass NOTEs before even knowing the basics... this makes me anxious... how wrong could things go!?

    • Installing With Restricted TLS

      not even sure what TLS is... Oh it's a good friend of SSL - Shouldn't this just be the default and just work out of the box? My browser can do HTTPS, NO PROBLEM! (just kidding... I know that SSL and TSL frequently cause a lot of pain in environments that have high security needs)

    • Option 1
    • Option 2

      eeh... great... Can't I just install?

    • Installing Behind a Proxy?

      Just... no...

    • Requirements

      uh boi...

    • Why does Chocolatey install where it does by default?

      Seriously!?!

    • Before You Install


      (source: clipartbest.com)

    • Can I install with a proxy?

      again with the proxy...

    • Can I install a particular version of Chocolatey?

      just any version would be fine, thank you...

    • Can I use Windows built-in compression instead of downloading 7zip?

      7zip?! Why do you even mention this?!

    • Non-Administrative Install
    • Now that sounds great!

      • "NOTE: This option should be a last resort and is considered to be an advanced scenario."
        • Sh$%!@T.

    • Alternative Installation Options

      giddy

    • Command Line
      • "This really is the easiest method because it requires no configuration of PowerShell prior to executing it."

        And there you go!

    While I really appreciate the fact that pitfalls and their possible solutions are discussed so extensively, maybe re-organizing them as such, and putting the Chocolatey installs in seconds promise to work by putting the "easiest method" first would be just awesome!

提交回复
热议问题