node.js 安装Node.js 安装n 安装Node.js?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19451851/
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
Install Node.js to install n to install Node.js?
提问by Golo Roden
I have a problem understanding the use of n. Basically, it is clear that it is a version manager for Node.js such as nvm.
我在理解n的使用时遇到问题。基本上,很明显它是 Node.js 的版本管理器,例如nvm。
But in contrast to nvm, which is basically a shell script, according to the documentation you are encouraged to use npm to install n:
但与 nvm 相比,它基本上是一个 shell 脚本,根据文档,你被鼓励使用 npm 来安装n:
$ npm install -g n
What I don't get is: For having npmat hand you need to install Node.js. Why would I install Node.js manually to use npmto then be able to install Node.js using n?
我不明白的是:为了npm手头,你需要安装 Node.js。为什么我要手动安装 Node.js npm,然后才能使用 n 安装 Node.js?
To put my question in other words: Why does n suggest installing using npm, if its main purpose is to install Node.js, which includes npm?
换句话说:为什么 n 建议安装 using npm,如果它的主要目的是安装 Node.js,其中包括 npm?
采纳答案by mklement0
tl; dr
tl; 博士
# Installs n and the latest LTS Node.js version to ~/n.
# For bash, ksh, zsh, modifies the respective user-specific shell-initialization file to
# define env. variable N_PREFIX and append $N_PREFIX/bin to the $PATH.
curl -L https://git.io/n-install | bash
I feel your pain. Installing Node.js to then install nto then manage Node.js installations is indeed a strange setup.
我感觉到你的痛苦。安装 Node.js 然后安装n然后管理 Node.js 安装确实是一个奇怪的设置。
It would indeed be great to be able to install nby itself first.
能够首先自行安装确实很棒n。
I've created a projectto support installation of ndirectly from GitHub; the only prerequisite beyond what nitself needs is git.
我创建了一个项目来支持n直接从 GitHub安装;超越n自身需要git的唯一先决条件是。
Note that you must first remove any pre-existing n/ Node.js versions.
The target directory, ~/nby default, must either not yet exist or be empty.
For bash, ksh, and zsh, the relevant shell initialization file (e.g., ~/.bashrc) is automatically modified to define environment variable N_PREFIXand append $N_PREFIX/binto the $PATH; for other shells, this must be done manually.
请注意,您必须首先删除任何预先存在的n/ Node.js 版本。默认情况下,
目标目录~/n必须不存在或为空。
对于bash, ksh, and zsh,相关的 shell 初始化文件(例如,~/.bashrc)会自动修改以定义环境变量N_PREFIX并附$N_PREFIX/bin加到$PATH; 对于其他外壳,这必须手动完成。
Aside from installing ndirectly from GitHub, it also installs helper scripts for updating n(n-update) and uninstalling it (n-uninstall).
除了n直接从 GitHub安装外,它还安装用于更新n( n-update) 和卸载 ( n-uninstall) 的帮助脚本。
Here are working examples; see the n-install GitHub repofor details:
以下是工作示例;有关详细信息,请参阅n-install GitHub 存储库:
Installation with confirmation prompt to confirm installing to default location
$HOME/nand installing the latest LTS Node.js version:curl -L https://git.io/n-install | bashAutomated installation to the default location, with subsequent installation of the latest LTS (long-term support) and latest-overall Node.js versions, as well as the latest 4.1.x Node.js version:
curl -L https://git.io/n-install | bash -s -- -y lts latest 4.1Automated installation to the default location, withoutsubsequent installation of a Node.js version:
curl -L https://git.io/n-install | bash -s -- -y -Automated installation to custom location
~/util/n, with subsequent installation of the latest LTS Node.js version:curl -L https://git.io/n-install | N_PREFIX=~/util/n bash -s -- -y
安装带有确认提示以确认安装到默认位置
$HOME/n并安装最新的 LTS Node.js 版本:curl -L https://git.io/n-install | bash自动安装到默认位置,随后安装最新的 LTS(长期支持)和最新的整体 Node.js 版本,以及最新的 4.1.x Node.js 版本:
curl -L https://git.io/n-install | bash -s -- -y lts latest 4.1自动安装到默认位置,无需后续安装 Node.js 版本:
curl -L https://git.io/n-install | bash -s -- -y -自动安装到自定义位置
~/util/n,随后安装最新的 LTS Node.js 版本:curl -L https://git.io/n-install | N_PREFIX=~/util/n bash -s -- -y
回答by user456584
If you prefer, you can install n from source:
如果您愿意,可以从源代码安装 n:
cd /tmp
git clone --depth=1 https://github.com/tj/n
cd n
sudo make install
Then you can install the latest stable version of node as follows:
然后你可以安装最新的稳定版node,如下:
n stable
回答by hexacyanide
The nmodule was created for convenience.
该ñ模块是为创造便利。
For example, if you wanted to update your version of Node.js from v0.8.0 to v0.10.20, would you rather download a package, extract and compile? Or would you rather type n 0.10.20and have it instantly installed, while still retaining previous versions of Node for easy switching?
例如,如果您想将您的 Node.js 版本从 v0.8.0 更新到 v0.10.20,您是否更愿意下载一个包、解压和编译?或者您更愿意输入n 0.10.20并立即安装它,同时仍然保留以前版本的 Node 以便于切换?
nsuggests using npmto install it because nis a module. That is, npmis the easiest way to install it. Node modules have the functionality of being able to run in a shell when installed globally, so that function was utilized to make switching Node versions much easier.
n建议使用npm来安装它,因为n是一个模块。也就是说,npm是最简单的安装方式。Node 模块具有在全局安装时能够在 shell 中运行的功能,因此利用该功能可以更轻松地切换 Node 版本。
回答by A T
You can also install npmseparately from Node.JS; e.g.: on a system without Node.JS:
您也可以npm与 Node.JS 分开安装;例如:在没有 Node.JS 的系统上:
git clone https://github.com/npm/npm
cd npm
./configure
make
Reference: NPM GitHub project
回答by Crooner
I had the same question, but have seen the light. 'n' is a handy tool and makes it simple to test different versions of node. Works great on Linux, but no matter how I try to install it on OS X (git clone, then npm install or using user456584's recommended method), when I run it, I always get the same results of "Error: no installed version", even though it installs into
我有同样的问题,但已经看到了曙光。“n”是一个方便的工具,可以轻松测试不同版本的节点。在 Linux 上运行良好,但无论我如何尝试在 OS X 上安装它(git clone,然后 npm install 或使用user456584的推荐方法),当我运行它时,我总是得到相同的结果“错误:未安装版本”,即使它安装到
/usr/local/lib/node_modules/n
/usr/local/lib/node_modules/n
and
和
/usr/local/bin/n
/usr/local/bin/n
Frustrating because I've found this tool to be so handy on Linux.
令人沮丧,因为我发现这个工具在 Linux 上非常方便。
回答by r.bhardwaj
If you have included your default node bin in the $PATH variable like this
如果您已将默认节点 bin 包含在 $PATH 变量中,如下所示
export PATH=/usr/local/Cellar/node/11.5.0/bin:$PATH
then n will not be able to active other node versions. Remove this export from the path and then you can manage the currently active node version by n.
那么 n 将无法激活其他节点版本。从路径中删除此导出,然后您可以通过 n 管理当前活动的节点版本。

