node.js 如何在 Windows 上以本地用户身份安装 NodeJS LTS(没有管理员权限)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37029089/
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 20:10:38  来源:igfitidea点击:

How to install NodeJS LTS on Windows as a local user (without admin rights)

node.jswindowsnpm

提问by Anthony O.

I'm using Windows as a simple user (I don't have any admin rights) and want to install NodeJS LTS.

我使用 Windows 作为一个简单的用户(我没有任何管理员权限)并且想要安装 NodeJS LTS。

On the download siteI have the choice to download only the binary node.exe(which don't includes npm) or the node.msiinstaller which requires the admin rights to execute.

下载站点上,我可以选择仅下载二进制文件node.exe(不包括npm)或node.msi需要管理员权限才能执行的安装程序。

How can I manually install node.exeand also be able to use npm?

如何手动安装node.exe并能够使用npm

回答by Anthony O.

Let say you want to install it into %userprofile%\Applications\nodejs-lts, let's name it <NODE_PATH>.

假设您想将其安装到 中%userprofile%\Applications\nodejs-lts,让我们将其命名为<NODE_PATH>.

  1. Downloadthe LTS node.exebinary for Windows and copy it to <NODE_PATH>.

  2. Add <NODE_PATH>to your PATHenvironment variable (set PATH=<NODE_PATH>;%PATH%or using Windows user interface)

  3. Download the stable at https://registry.npmjs.org/npm/-/npm-{VERSION}.tgznpm package (following the documentation)

  4. Unzip the npm-{VERSION}.tgzanywhere (using 7zipfor example)

  5. Launch a cmdand cdinto the place where you have unzipped npm

  6. Execute: node cli.js install -gfor node bin/npm-cli.js install npm -gfon certain versions (thanks to this comment)

  1. 下载node.exe适用于 Windows的 LTS二进制文件并将其复制到<NODE_PATH>.

  2. 添加<NODE_PATH>到您的PATH环境变量(set PATH=<NODE_PATH>;%PATH%或使用Windows 用户界面

  3. https://registry.npmjs.org/npm/-/npm-{VERSION}.tgznpm 包下载稳定版(按照文档

  4. 解压缩npm-{VERSION}.tgz任何地方(例如使用7zip

  5. 启动 acmdcd进入您解压 npm 的位置

  6. 执行:node cli.js install -gfnode bin/npm-cli.js install npm -gf在某些版本上(感谢此评论

The last command is specified in the Makefilefor target install, target which the README.mdinvites to execute when manually installing.

最后一个命令在Makefilefor target 中指定,手动安装时邀请执行的install目标README.md

UPDATE 10/2018

更新 10/2018

On Node's download page referenced in step 1. there is now a .zip archive downloadwhich contains both the nodejs executable and npm. Unpacking that to a suitable path and adding this path to your PATH environment variable (step 2.) will give you both node and npm (so you can skip steps 3. - 6.).

在步骤 1 中引用的 Node 下载页面上,现在有一个.zip 存档下载,其中包含nodejs 可执行文件和 npm。将其解压到合适的路径并将此路径添加到您的 PATH 环境变量(步骤 2.)将为您提供 node 和 npm(因此您可以跳过步骤 3. - 6.)。

回答by joerno

The nodejs version of 6.11 LTS and later seems to be easier to install, because npm is already included.

6.11 LTS 及更高版本的 nodejs 版本似乎更容易安装,因为已经包含了 npm。

  1. Download the node.js LTS binary for Windowsand extract it to your desired location
  2. Add the path of the nodejs folder to the PATH environment variable: (Shortcut winkey+R and enter: rundll32 sysdm.cpl,EditEnvironmentVariables)
  3. Open a new command window (winkey+R and type cmd)
  4. Type node -vand npm -vto verify the installation
  1. 下载适用于 Windowsnode.js LTS 二进制文件并将其解压缩到所需位置
  2. 所述的的NodeJS路径添加文件夹到PATH环境变量:(快捷键WINKEY + R和输入:rundll32 sysdm.cpl,EditEnvironmentVariables
  3. 打开一个新的命令窗口(winkey+R 并输入cmd
  4. 键入node -vnpm -v以验证安装

回答by chidimo

Just download the windows binary (NOT the msi installer) from here, unzip the file, then add the location of the node.exefile to system path. This means that after unzipping the downloaded binary, you get a folder, then you have to open that folder itself. That is the path you should add to system path.

只需从这里下载 Windows 二进制文件(不是 msi 安装程序),解压缩文件,然后将文件的位置添加node.exe到系统路径。这意味着在解压下载的二进制文件后,您会得到一个文件夹,然后您必须打开该文件夹本身。这是您应该添加到系统路径的路径。

To add to system path, do this, thanks to Abdel Raoof

要添加到系统路径,请执行此操作,感谢Abdel Raoof

Open Run with dialog (Win + R). Copy and paste this line in your command line

打开运行对话框(Win + R)。将此行复制并粘贴到命令行中

rundll32 sysdm.cpl,EditEnvironmentVariables.

rundll32 sysdm.cpl,EditEnvironmentVariables.

In User variables for user_name(the top window) path of your environment variables dialog add the path to your unzipped node download. To check for successful installation

在环境变量对话框的user_name(顶部窗口)路径的用户变量中,添加解压缩节点下载的路径。检查安装是否成功

node -v

npm -v

回答by Bhargav

  1. Download the node.js zip file from official page. https://nodejs.org/en/download/
  2. Unzip the file.
  3. Goto Edit Environment Variables For Your Account.
  4. Add new path /node-v10.14.2-win-x64\node-v10.14.2-win-x64
  5. That's it... now you have installed both node.js and npm.
  6. Use node -vand npm -vto check installation.
  1. 从官方页面下载 node.js zip 文件。https://nodejs.org/en/download/
  2. 解压缩文件。
  3. 转到为您的帐户编辑环境变量
  4. 添加新路径/node-v10.14.2-win-x64\node-v10.14.2-win-x64
  5. 就是这样……现在你已经安装了 node.js 和 npm。
  6. 使用node -vnpm -v检查安装。

回答by Rahamath

Add following paths to the PATHenvironment variable, if you have downloaded the Node.js Windows Binary (.zip)

PATH如果您已下载 Node.js Windows 二进制文件 (.zip),请将以下路径添加到环境变量中

  1. <your os root>\node-v10.16.1-win-x64\
  2. <your os root>\node-v10.16.1-win-x64\node_modules\npm\bin\
  1. <your os root>\node-v10.16.1-win-x64\
  2. <your os root>\node-v10.16.1-win-x64\node_modules\npm\bin\

Then test following commands from the command prompt:

然后从命令提示符测试以下命令:

node -v

nmp -v

回答by RPS

The answer provided is too old now. Portable download for Node (including NPM) is available as a zip download and it word just out of the box. you just need to add the folder to the path.

提供的答案现在太旧了。Node 的便携式下载(包括 NPM)可以 zip 下载的形式提供,并且开箱即用。您只需要将文件夹添加到路径中。

回答by Imran

For nodeportable installation in windows batch file with below command can also be created in node root directory(where node.exefile resides) which updates PATHenvironment variable on execution and also directly through command prompt from node root directory

对于使用以下命令在 Windows 批处理文件中的节点便携式安装,也可以在节点根目录(node.exe文件所在的位置)中创建,该目录在执行时更新PATH环境变量,也可以直接通过节点根目录的命令提示符

PATH %~dp0;%PATH%;

~dp0 : fetches current directory path in windows

~dp0 : 在 windows 中获取当前目录路径

Hopes that Helps

希望有所帮助

回答by jeppoo1

Source: https://medium.com/@github.gkarthiks/how-to-install-nodejs-and-npm-in-non-admin-access-windows-machines-102fd461b54c:

来源:https: //medium.com/@github.gkarthiks/how-to-install-nodejs-and-npm-in-non-admin-access-windows-machines-102fd461b54c



Step 1:Download the nodeJS.exe file from https://nodejs.org/en/download/by clicking on All download options (example: https://nodejs.org/dist/v12.16.1/) and choose the right Windows architecture and download it.

步骤 1:通过单击所有下载选项(例如:https ://nodejs.org/dist/v12.16.1/)从https://nodejs.org/en/download/下载 nodeJS.exe 文件并选择正确的Windows 架构并下载它。

Step 2:Choose a folder for nodeJS. For example, C:\ProgramData\Applications\nodejs and save the downloaded file under this folder.

第 2 步:为 nodeJS 选择一个文件夹。例如,C:\ProgramData\Applications\nodejs 并将下载的文件保存在此文件夹下。

Step 3:Add the nodeJS folder to the environment variable PATH by executing the below command in the cmd.exe, or using the User Interface. set PATH=C:\ProgramData\Applications\nodejs;%PATH% OBS! Remember to restart your computer after setting the environment variable. (Windows 10)

第 3 步:通过在 cmd.exe 中执行以下命令或使用用户界面,将 nodeJS 文件夹添加到环境变量 PATH。设置 PATH=C:\ProgramData\Applications\nodejs;%PATH% OBS!设置好环境变量后记得重启电脑。(Windows 10)

Step 4:Now download the stable version of npm from the below link by replacing the version. https://registry.npmjs.org/npm/-/npm-{VERSION}.tgz For example for npm version 6.4.1,https://registry.npmjs.org/npm/-/npm-6.4.1.tgz

第 4 步:现在通过替换版本从以下链接下载稳定版本的 npm。 https://registry.npmjs.org/npm/-/npm-{VERSION}.tgz 例如,对于 npm 6.4.1 版,https: //registry.npmjs.org/npm/-/npm-6.4.1 。 tgz

Step 5:Now unzip the downloaded npm file anywhere and cd into package folder. (I used convert.io to convert tgz to zip for unzipping in Windows 10 https://convertio.co/tgz-converter/)

第 5 步:现在将下载的 npm 文件解压到任意位置并 cd 到包文件夹中。 (我使用 convert.io 将 tgz 转换为 zip 以在 Windows 10 https://convertio.co/tgz-converter/ 中解压)

Step 6:Execute the following command in the cmd.exe

第六步:在cmd.exe中执行以下命令

node bin/npm-cli.js install npm -gf

Step 7:Execute the following commands to verify the installation of nodeJS and npm.

第七步:执行以下命令验证nodeJS和npm的安装。

node -v
npm -v

回答by jdunning

As others have pointed out, npm is now included with the binary (.zip) node download. So installing node and npm without admin rights is straightforward, though you need to manually add the node directory to the PATHenvironment variable.

正如其他人指出的那样,npm 现在包含在二进制 (.zip)节点下载中。所以在没有管理员权限的情况下安装 node 和 npm 很简单,尽管您需要手动将 node 目录添加到PATH环境变量中。

However, as of v8.11.4, the binary was including npm v5.6.1. Running npm install npm@latest -gcomplained about not being able to delete npm.cmdand npx.cmd. Moving those files out of the node directory fixes that, but then you can't simply run npmon the command line, because npm.cmdis no longer on the node path.

但是,从 v8.11.4 开始,二进制文件包含 npm v5.6.1。运行npm install npm@latest -g抱怨无法删除npm.cmdnpx.cmd。将这些文件移出节点目录修复了这个问题,但是你不能简单地npm在命令行上运行,因为npm.cmd不再在节点路径上。

Trying @Anthony O's approach of downloading the latest npm .zip and installing from there didn't work either, as it was complaining about rimrafnot being installed. It seemed like maybe the npm install script was assuming rimrafwas installed globally.

尝试@Anthony O 下载最新的 npm .zip 并从那里安装的方法也不起作用,因为它抱怨rimraf没有安装。似乎 npm install 脚本假设rimraf是全局安装的。

What finally worked was changing to the node directory and specifying the full path to npm-cli.jsfrom there:

最终起作用的是更改到节点目录并指定npm-cli.js从那里开始的完整路径:

node node_modules/npm/bin/npm-cli.js install -g npm@latest

I see that the node v8.12.0 package that was just released now includes npm v6.4.1, so the above shouldn't be necessary for now.

我看到刚刚发布的 node v8.12.0 包现在包含 npm v6.4.1,所以现在应该不需要上面的。

回答by Nebu

Accepted answer from @Anothony O. didn't work for me. If got it working following theseinstructions and by adding the following to node\node_modules\npm\npmrc

@Anthony O. 接受的答案对我不起作用。如果按照这些说明进行操作并将以下内容添加到 node\node_modules\npm\npmrc

strict-ssl=false