在 Windows 上安装 npm(Node.js 包管理器)(不使用 Node.js MSI)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16000173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:12:52  来源:igfitidea点击:

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

node.jsinstallnpm

提问by

The problem: while using nvmto install Node.js I was able to install the version of Node.js I need, but nvmdoes not install npmautomatically. NPM's page provides no information about installing it. Being not much of a Windows user myself I am completely at a loss...

问题:在nvm用于安装 Node.js 时,我能够安装我需要的 Node.js 版本,但nvm不会npm自动安装。NPM 的页面没有提供有关安装它的信息。我自己并不是一个 Windows 用户,我完全不知所措......

Every result in Google seems to use Node.js MSI installer to get that working - which is not an option in my case. So, how do I?

Google 中的每个结果似乎都使用 Node.js MSI 安装程序来使其正常工作 - 在我的情况下这不是一个选项。那么,我该怎么办?

回答by user568109

To install npm on windows just unzip the npm archivewhere node is. See the docsfor more detail.

要在 Windows 上安装 npm,只需解压缩node 所在的 npm存档。有关更多详细信息,请参阅文档

npm is shipped with node, that is how you should install it. nvm is only for changing node versions and does not install npm. A cleaner way to use npm and nvm is to first install node as it is (with npm), then install the nvmpackage by npm install nvm

npm 与 node 一起提供,这就是你应该如何安装它。nvm 仅用于更改节点版本,不安装 npm。使用 npm 和 nvm 的一种更简洁的方法是首先按原样安装节点(使用 npm),然后通过以下方式安装nvmnpm install nvm

回答by Manas

https://nodejs.org/download/. The page has Windows Installer (.msi) as well as other installers and binaries.Download and install for windows.

https://nodejs.org/download/。该页面包含 Windows 安装程序 (.msi) 以及其他安装程序和二进制文件。为 Windows 下载并安装。

Node.js comes with NPM.

Node.js 带有 NPM。

NPM is located in the directory where Node.js is installed.

NPM 位于安装 Node.js 的目录中。

回答by Christophe

I used quite @Eyuel method:

我使用了相当@Eyuel 方法:

  • Download the nodejs msi from https://nodejs.org/en/#download
  • Download npm zip from github https://github.com/npm/npm
  • Extract the msi (with 7 Zip) in a directory "node"
  • Set the PATH environment variable to add the "node" directory
  • Extract the zip file from npm in a different directory (not under node directory)
  • CD to the npm directory and run the command node cli.js install npm -gf
  • https://nodejs.org/en/#download下载 nodejs msi
  • 从 github https://github.com/npm/npm下载 npm zip
  • 在目录“节点”中提取 msi(带有 7 Zip)
  • 设置PATH环境变量添加“node”目录
  • 将 zip 文件从 npm 解压到不同目录(不在 node 目录下)
  • CD到npm目录并运行命令 node cli.js install npm -gf

Now you should have node + npm working, use theses commands to check: node --versionand npm --version

现在你应该有节点+ NPM工作,使用学位论文的命令检查:node --versionnpm --version

Update 27/07/2017: I noticed that the latest version of node 8.2.1 with the latest version of npm are quite different from the one I was using at the time of this answer. The install with theses versions won't work. It is working with node 6.11.1 and npm 5.2.3. Also if you are running with a proxy don't forget this to connect on internet :

2017 年 7 月 27 日更新:我注意到最新版本的 node 8.2.1 和最新版本的 npm 与我在回答这个问题时使用的版本大不相同。这些版本的安装将不起作用。它适用于节点 6.11.1 和 npm 5.2.3。此外,如果您使用代理运行,请不要忘记连接互联网:

回答by slashCoder

I also needed to install npm in Windows and got it through the Chocolatey pacakage manager. For those who haven't heard about it, Chocolatey is a package manager for Windows, that gives you the convenience of an apt-get in Windows environments. To get it go to https://chocolatey.org/where there's a PowerShell script to download it and install it. After that you can run:

我还需要在 Windows 中安装 npm 并通过 Chocolatey pacakage 管理器获得它。对于那些没有听说过它的人,Chocolatey 是 Windows 的包管理器,它为您提供了 Windows 环境中 apt-get 的便利。要获取它,请访问https://chocolatey.org/,那里有一个 PowerShell 脚本可以下载并安装它。之后你可以运行:

chocolatey install npm

and you're good to go.

你可以走了。

Note that the standalone npm is no longer being updated and the last version that is out there is known to have problems on Windows. Another option you can look at is extracting npm from the MSI using LessMSI.

请注意,独立 npm 不再更新,并且已知最新版本在 Windows 上存在问题。您可以查看的另一个选项是使用LessMSI从 MSI 中提取 npm 。

回答by LoganMzz

Just download "node.exe" from http://nodejs.org/dist/, select your favorite "node.js" version or take the latest. You can also take 64-bits version from "x64" sub-directory.

只需从http://nodejs.org/dist/下载“node.exe” ,选择您最喜欢的“node.js”版本或使用最新的. 您还可以从“x64”子目录中获取 64 位版本。

Then, go to http://nodejs.org/dist/npm/to retrieve Zip-archive of your favorite "npm" version (recommanded : 1.4.10). Extract the archive along "node.exe".

然后,转到http://nodejs.org/dist/npm/以检索您最喜欢的“npm”版本的 Zip-archive(推荐 : 1.4.10)。沿着“node.exe”提取存档。

Finally, it is recommanded to add "node.js" directory to the PATH for convenience.

最后,为方便起见,建议将“node.js”目录添加到PATH。

EDIT: I recommande to update npm using npm install npm -gbecause versions provided by nodejs.org are very old.

编辑:我建议使用更新 npm,npm install npm -g因为 nodejs.org 提供的版本非常旧。

If you want to keep original npm version, don't put npm alongside "node.exe". Just create a directory and use the same command with "global" flag, then copy .\node_modules\.bin\npm.cmdto the new directory :

如果您想保留原始 npm 版本,请不要将 npm 放在"node.exe". 只需创建一个目录并使用带有“global”标志的相同命令,然后复制.\node_modules\.bin\npm.cmd到新目录:

mkdir c:\app\npm\_latest
cd c:\app\npm\_latest
<NPM_ORIGINAL_PATH>\npm install npm
cp node_modules\.bin\npm.cmd npm.cmd

Finally change your PATH to use c:\app\npm\_latest

最后更改您的 PATH 以使用 c:\app\npm\_latest

回答by Eyuel

First CD to where node(nodejs) is installed using windows CMD, then follow the steps below

使用windows CMD首先CD到安装node(nodejs)的位置,然后按照以下步骤操作

C:...\node> git config --system http.sslcainfo /bin/curl-ca-bundle.crt
C:...\node> git clone --recursive git://github.com/isaacs/npm.git
C:...\node> cd node=modules\npm
C:...\node=modules\npm> node cli.js install npm -gf

回答by noobius

I wrote a quick simple app recent that handle the management of various version of node and npm. It allows you to choose different version of node and npm to download and select which version to use. Check it out and see if it's something that's useful.

我最近写了一个快速简单的应用程序,处理各种版本的 node 和 npm 的管理。它允许您选择不同版本的 node 和 npm 来下载并选择要使用的版本。检查一下,看看它是否有用。

https://github.com/nhatkthanh/wnm

https://github.com/nhatkthanh/wnm

回答by fatih tekin

Try going to Window -> Preferences -> Nodeclipse and unchecking the box that says "find node on PATH...". Then make sure the "Node.js path" below is set to the location of the node.exe file (for me it was C:\Program Files (x86)\nodejs\node.exe).

尝试转到 Window -> Preferences -> Nodeclipse 并取消选中“在 PATH 上查找节点...”框。然后确保将下面的“Node.js 路径”设置为 node.exe 文件的位置(对我来说是 C:\Program Files (x86)\nodejs\node.exe)。

回答by Erik

Download the latest Node.js MSI (4.x or 5.x) installer and run the following via command line:

下载最新的 Node.js MSI(4.x 或 5.x)安装程序并通过命令行运行以下命令:

msiexec /a node-v4.4.3-x64.msi /qb TARGETDIR="C:\Node.js"

This will extract the binaries into C:\Node.js\nodejs.

这会将二进制文件提取到C:\Node.js\nodejs.

Then you will want to add C:\Node.js\nodejsPATHenvironment variable.

然后你会想要添加C:\Node.js\nodejsPATH环境变量。

To update NPM, do the following:

要更新 NPM,请执行以下操作:

cd C:\Node.js\nodejs
npm install npm@latest

After that completes, you should be able to check the versions:

完成后,您应该能够检查版本:

node --version
npm --version

Node should be 4.4.3+ (whichever you installed) and npm should be 3.8.7+.

Node 应该是 4.4.3+(无论你安装哪个),npm 应该是 3.8.7+。

回答by Domi

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

TL;DR:安装 Chocolatey、Node(和 NPM)

Install Chocolatey

安装巧克力

NOTE: You might want to copy the exact command from their install pagesince 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!
  1. 打开标准的 Windows 命令行
  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. 重启控制台
  4. 完毕!

Install Node (and NPM)

安装节点(和 NPM)

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

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

  4. Restart your console
  5. Beware: node -vworks!
    • And npm -valso works! Awesome.
  1. 因为 Chocolatey 安装的目录与 MSI 安装的目录不同,请转到您的系统配置并删除您之前的node安装(如果您有的话)
  2. 如上所述安装 Chocolatey
  3. choco install nodejs

    注意我使用了nodejs. 我什至不确定是什么node,但是我node已经因为已经被其他系统中的其他东西所占据而遇到了相当大的麻烦,我认为,nodejs马上会是更安全的赌注

  4. 重启你的控制台
  5. 当心:node -v有效!
    • 而且npm -v也有效!惊人的。

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

在此之后,我能够firebase-tools毫无问题地安装(我以前无法做到),所以一定是非常正确的!:)

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;DRsection below.

如果您不在乎周日下午的讽刺或哀叹工程师,请跳到下面TL;DR部分中的安装说明。

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

对于其他人:我想修改这个建议使用的答案(现在似乎是最热门的 Windows 包管理解决方案):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 TLSis... 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 SSLand TSLfrequently 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

    sad
    (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!

  • 笔记:
  • 笔记:
  • 笔记:

    在了解基础知识之前,三个大屁股笔记......这让我很焦虑......事情怎么会出错!?

  • 使用受限 TLS 安装

    甚至不确定是什么TLS......哦,它是SSL-的好朋友- 这不应该只是默认设置并且开箱即用吗?我的浏览器可以做到HTTPS,没问题!(开个玩笑……我知道这一点,SSL并且TSL经常在具有高安全需求的环境中造成很多痛苦)

  • 选项1
  • 选项 2

    呃......太好了......我不能安装吗?

  • 在代理后面安装?

    就是不行...

  • 要求

    呃,博...

  • 为什么 Chocolatey 默认安装在它安装的地方?

    严重地!?!

  • 安装之前

    伤心
    (来源:clipartbest.com

  • 我可以用代理安装吗?

    再次与代理...

  • 我可以安装特定版本的 Chocolatey 吗?

    任何版本都可以,谢谢...

  • 我可以使用 Windows 内置压缩而不是下载 7zip 吗?

    7zip?!你怎么还提这个?!

  • 非管理安装
  • 现在听起来很棒!

    • "注意:此选项应该是最后的手段,被视为高级方案。
      • Sh$%!@T。

  • 替代安装选项

    头晕

  • 命令行
    • “这确实是最简单的方法,因为它在执行之前不需要配置 PowerShell。”

      你去吧!

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 secondspromise to work by putting the "easiest method" first would be just awesome!

虽然我真的很欣赏这样一个事实,即如此广泛地讨论了陷阱及其可能的解决方案,但也许将它们重新组织起来,并Chocolatey installs in seconds通过将“最简单的方法”放在首位来实现承诺,这真是太棒了!