node.js 把它的文件放在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16479699/
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
Where does node.js put its files?
提问by mik01aj
I have recently started playing with node.js, but I got lost in a big mess of different versions of node, npm, nvm and other packages. I don't know what is installed globally and what is installed locally (and if locally, how do the packages know which versions of node they can use?).
我最近开始玩 node.js,但是我在一堆不同版本的 node、npm、nvm 和其他包中迷失了方向。我不知道什么是全局安装的,什么是本地安装的(如果在本地,包如何知道它们可以使用哪些版本的节点?)。
I'd like to have some summary of what different installation options do. In specific:
我想总结一下不同安装选项的作用。具体来说:
- Where is node installed when I use
nvm,apt-get,make installor when using other ways? - Is it a good idea to install node locally?
- Why does
nvmchange my~/.profileinstead of installing itself in some system-recognizablebinfolder? - I saw that
nvmcan install different versions of node alongside each other - why would I want to do this? I can install them locally instead, right? - Where does
npminstall packages? I saw that it checks packages aganist version of Node, what happens to these packages when node is upgraded? - In what cases it is better to use global or local installation? Where should I put my packages then (and where they put by default?)
- What's the difference between
npm,nvmandnave?
- 当我使用、或使用其他方式时
nvm,节点安装在哪里?apt-getmake install - 在本地安装节点是个好主意吗?
- 为什么在某些系统可识别的文件夹中
nvm更改我~/.profile而不是将其自身安装bin? - 我看到
nvm可以同时安装不同版本的节点 - 我为什么要这样做?我可以在本地安装它们,对吗? npm安装包在哪里?我看到它检查了 Node 的包 aganist 版本,当节点升级时这些包会发生什么?- 在什么情况下最好使用全局安装或本地安装?那么我应该把我的包裹放在哪里(默认情况下它们放在哪里?)
- 什么之间的区别
npm,nvm以及nave?
EDIT: There is a lot of ways to install node here, this makes me even more confused...
编辑:有很多方法可以在这里安装节点,这让我更加困惑......
回答by Igor Malyk
Where is node installed when I use nvm, apt-get, make install or when using other ways?
当我使用 nvm、apt-get、make install 或使用其他方式时,node 安装在哪里?
apt-get installs all the software, not only node, on the file system following the Ubuntu convention where to store binaries, man files, shared files, logs, etc. However, using apt-get you'll have only the certain version of node which is determined by the distribution release cycle. If there are updates available they will be installed with apt-get update; apt-get upgradeHowever, the newest version of some app won't be available until it makes its way into the distribution. For example node v0.x.y might not be available until Ubuntu 13.10 the only way to get will be to install it manually. The good side of apt-getor other system package manager is that it manages updates and package removal for you. It stores all the data about the software package in it's own database. You can always delete the node with apt-get remove nodeand that's it.
apt-get 按照 Ubuntu 约定在文件系统上安装所有软件,而不仅仅是 node由分发发布周期决定的节点。如果有可用的更新,它们将被安装。apt-get update; apt-get upgrade但是,某些应用程序的最新版本在进入发行版之前将不可用。例如,节点 v0.xy 可能在 Ubuntu 13.10 之前不可用,唯一的获取方法是手动安装它。apt-get或其他系统包管理器的好处是它可以为您管理更新和包删除。它将有关软件包的所有数据存储在自己的数据库中。您可以随时删除节点,仅apt-get remove node此而已。
make installinstall the package manually, but it is considered harmful. Never use the make installmainly because you won't be able to delete the package easily, you'll have to read the Makefile and manually delete all the files installed by it. In a situation where you want to use make installthere is always checkinstallavailable. It's a software which creates a native package and registers it with the system. When you decide to delete the package you could do this with one command instead of many. wiki link; Ubuntu guide on checkinstall
make install手动安装软件包,但它被认为是有害的。永远不要使用,make install主要是因为您无法轻松删除软件包,您必须阅读 Makefile 并手动删除它安装的所有文件。在您要使用的情况下,make install始终checkinstall可用。它是一种创建本机包并将其注册到系统的软件。当您决定删除包时,您可以使用一个命令而不是多个命令来执行此操作。维基链接;checkinstall 上的 Ubuntu 指南
Now nvmscript is a node version manager. It is very helpful and easy to use. It allows you to have multiple versions of node to be installed and used in parallel on your machine. It doesn't compile the node from source like make installso it is very fast. it doesn't depend on your distribution release cycle so you have access to all the node versions available at the moment. nvm downloads precompiled binaries and is perfect for general use. It stores it's node files in it's own folder locally so in case you want to compare something between the different node versions it's easy to do.
现在nvm脚本是一个node version manager. 它非常有用且易于使用。它允许您在机器上并行安装和使用多个版本的节点。它不像从源代码那样编译节点,make install所以它非常快。它不取决于您的发行版发布周期,因此您可以访问目前可用的所有节点版本。nvm 下载预编译的二进制文件,非常适合一般使用。它将它的节点文件存储在它自己的本地文件夹中,因此如果您想比较不同节点版本之间的某些内容,这很容易做到。
Is it a good idea to install node locally?
在本地安装节点是个好主意吗?
If by locally you mean using nvmthen it's very good for development, and testing. Not sure about production performance implications and benefits between having it's installed from source or using the nvmprecompiled binaries. I use nvm for development and installed from source in production. However if someone could explain this issue any further I'll be glad to learn more.
如果您的意思是在本地使用,nvm那么它非常适合开发和测试。不确定从源代码安装或使用nvm预编译二进制文件之间的生产性能影响和好处。我使用 nvm 进行开发并在生产中从源代码安装。但是,如果有人可以进一步解释这个问题,我会很高兴了解更多信息。
Why does nvm change my ~/.profile instead of installing itself in some system-recognizable bin folder?
为什么 nvm 更改我的 ~/.profile 而不是将自己安装在某些系统可识别的 bin 文件夹中?
Because nvmisn't an executable. It is a set of bash functions which are sourced by shell and could be used separately. You can invoke nvm_lsand nvm_ls_remoteand others without the main script after is is sourced into your shell. What the main script does it parses the command line arguments and pretty prints the output in case of for example `nvm_ls_remote'.
因为nvm不是可执行文件。它是一组由 shell 提供的 bash 函数,可以单独使用。在将 is 输入到您的 shell 之后,您可以在没有主脚本的情况下调用nvm_lsandnvm_ls_remote和其他脚本。主脚本的作用是解析命令行参数并在例如“nvm_ls_remote”的情况下漂亮地打印输出。
in the ~/.profile the following line is added
在 ~/.profile 中添加以下行
[[ -s /home/USERNAME/.nvm/nvm.sh ]] && . /home/USERANME/.nvm/nvm.sh # This loads NVM
loads all the functions into your shell
将所有函数加载到你的 shell 中
I saw that nvm can install different versions of node alongside each other - why would I want to do this? I can install them locally instead, right?
我看到 nvm 可以同时安装不同版本的节点——我为什么要这样做?我可以在本地安装它们,对吗?
You can install them locally using make installor checkinstallbut you will have to make aliases for them like node_0.8.1, node_0.8.2, node_0.10.1 , etc. AND you'll have to manage new aliases, installing all the packages, removing them in case you don't need them YOURSELF. These are a tedious and boring tasks which could be error prone sometimes. nvmdoes all of these tasks for you for free.
您可以使用make install或在本地安装它们,checkinstall但您必须为它们创建别名,例如 node_0.8.1、node_0.8.2、node_0.10.1 等。并且您必须管理新别名、安装所有包、删除它们以防万一你自己不需要它们。这些是单调乏味的任务,有时容易出错。nvm免费为您完成所有这些任务。
You want to do this to test your app under the different versions of node. For example you are good and tested under the v0.8 but you want to use the new features of the v0.10.3 how do you do that ? You have to download the source code, compile, make an alias and run your app. you could do this with just nvm install 0.10.3and run your app.
Sometimes you have to support more than one version of node. For example some hosted environments are not keeping in touch with the latest release and only have v0.6 Your clients which use your server app might encounter a bug specific to this version. When you fix the bug you have to reproduce it first. Using nvminstallation of the v0.6 is one line and half a minute. And you can check all the versions you want this way easily. Test your code under different versions and make sure you are good to go.
您想这样做是为了在不同版本的节点下测试您的应用程序。例如,您在 v0.8 下测试良好,但您想使用 v0.10.3 的新功能,您该怎么做?您必须下载源代码、编译、创建别名并运行您的应用程序。你可以这样做nvm install 0.10.3并运行你的应用程序。有时您必须支持多个版本的节点。例如,一些托管环境不与最新版本保持联系,只有 v0.6 使用您的服务器应用程序的客户端可能会遇到特定于该版本的错误。当您修复错误时,您必须首先重现它。使用nvmv0.6的安装是一行半分钟。您可以通过这种方式轻松检查您想要的所有版本。在不同版本下测试您的代码并确保您一切顺利。
Where does npm install packages? I saw that it checks packages aganist version of Node, what happens to these packages when node is upgraded?
npm 在哪里安装包?我看到它检查了 Node 的包 aganist 版本,当节点升级时这些包会发生什么?
If you are using nvmthe packages which are installed globally with -goption are tied to the relevant node version. When you switch between versions with nvm use 0.xyou have to either install the packages again or use nvm copy-packages <version>to use the packages from in the current version. If the packages are installed locally then it depends. package.jsonshould contain info on the dependencies of the app. If it says node: '0.8' and you just updated to 0.9 you might encounter troubles. For example the behavior of process.nextTickwas changed in the latest releases compared to 0.6. So be careful.
如果您使用nvm的是带有-g选项的全局安装的软件包,则这些软件包与相关的节点版本相关联。当您在版本之间切换时,nvm use 0.x您必须再次安装软件包或使用nvm copy-packages <version>当前版本中的软件包。如果软件包安装在本地,则视情况而定。package.json应包含有关应用程序依赖项的信息。如果它显示 node: '0.8' 而你刚刚更新到 0.9 你可能会遇到麻烦。例如,process.nextTick与 0.6 相比,最新版本中的行为发生了变化。所以要小心。
In what cases it is better to use global or local installation? Where should I put my packages then (and where they put by default?)
在什么情况下最好使用全局安装或本地安装?那么我应该把我的包裹放在哪里(默认情况下它们放在哪里?)
It depends. For development nvmis superior in my opinion. For me it is convenient and simple. For production there are might be some performance implications when using the precompiled binary files not optimized for your system. It would be better to ask this as a separate question so the people with the relevant experience could answer.
这取决于。nvm在我看来,发展是优越的。对我来说,它既方便又简单。对于生产,使用未针对您的系统优化的预编译二进制文件时,可能会对性能产生一些影响。最好将其作为一个单独的问题提出,以便有相关经验的人可以回答。
What's the difference between npm, nvm and nave?
npm、nvm 和 nave 有什么区别?
npmis a node package manager-> linkIt contains userland packages developed by other people. These packages are not part of the node core. npm is used for publishing your code and dependency management. If your app requires other app developed by other people it is convenient to publish it via npm.
npm是一个 node package manager->链接它包含由其他人开发的用户空间包。这些包不是节点核心的一部分。npm 用于发布您的代码和依赖项管理。如果您的应用程序需要其他人开发的其他应用程序,那么通过 npm 发布它很方便。
nvmis a node version managerit does a completely separate thing. It gives you an ability to very easily switch between node versions on the same machine and manages all he changes in your $PATHenvironment variable.
nvm是一个node version manager完全独立的事情。它使您能够非常轻松地在同一台机器上的节点版本之间切换,并管理$PATH环境变量中的所有更改。
Consider nvmas update manager for the Operation System and npmas a manager of the applications for this system. Well, this comparison isn't precise but just came upon my mind
考虑nvm作为操作系统的更新管理器和npm该系统的应用程序的管理器。嗯,这个比较并不准确,只是我想到了
naveis basically the same as nvmbut it is an executable whereas nvmis a script which is sourced into the shell. Each system has it's own benefits. You could make a separate question regarding it's use cases and differences.
nave基本上相同,nvm但它是一个可执行文件,而它nvm是一个脚本,它来自于 shell。每个系统都有它自己的好处。您可以就它的用例和差异提出一个单独的问题。
My answer isn't 100% complete and contains a lot of subjective personal opinions. However, I hope I'll at least make some points more clear so you might proceed with other more specific questions. Btw, this question list of yours could be asked as separate questions. I believe stackoverflow gives best results when specific questions are asked separately and more people with relevant experience could contribute.
我的回答不是100%完整,包含很多主观的个人意见。但是,我希望我至少能把一些要点说得更清楚,这样你就可以继续处理其他更具体的问题。顺便说一句,您的这个问题列表可以作为单独的问题提出。我相信当单独询问特定问题时,stackoverflow 会提供最佳结果,并且更多具有相关经验的人可以做出贡献。
回答by Eugene
If you run
如果你跑
npm install
in folder with package.json, it installs all packages localy (in the current folder).
在带有 package.json 的文件夹中,它会在本地安装所有包(在当前文件夹中)。
Also, npm default install packeges local. To install it globaly - use -gflag:
此外,npm 默认安装包是本地的。要全局安装它 - 使用-g标志:
npm install -g <package>
Execute next command:
执行下一个命令:
npm config list
You see all npm config description.
您会看到所有 npm 配置说明。
回答by Lars Natus
You can install modules in the local context of your application with
您可以使用以下命令在应用程序的本地上下文中安装模块
npm install modulename
npm install modulename
In this case the module will be installed to your node_modules folder of your application.
在这种情况下,模块将安装到应用程序的 node_modules 文件夹中。
Otherwise you can install a module in the global context with
否则,您可以使用以下命令在全局上下文中安装模块
npm install -g modulename
npm install -g modulename
In this case the module will be installed for the hole system environment usually at /usr/local/bin/modulename.
在这种情况下,通常会在 /usr/local/bin/modulename 中为孔系统环境安装模块。
The global installation makes sense for modules you need in more than one application, like express or node-inspector.
全局安装对于您在多个应用程序中需要的模块很有意义,例如 express 或 node-inspector。

