简体   繁体   English

Nodejs,Npm,节点。 包装差异?

[英]Nodejs, Npm, node. Package difference?

Recently working with NodeJS ect. 最近使用NodeJS等。 I installed quite different packages, for different tutorials + projects. 我为不同的教程+项目安装了完全不同的软件包。 I finally ended up with this kind of configuration: 我最终得到了这种配置:

louis@louis:~$ node -v
v5.10.0
louis@louis:~$ nodejs -v
v6.2.1
louis@louis:~$ npm -v
3.8.3

Can you explain the difference between these? 你能解释一下这些之间的区别吗?

Your situation 你的情况

Seems you have two different versions of nodejs installed, possibly one was installed from sources and one from package manager like apt . 似乎你安装了两个不同版本的nodejs ,可能一个是从源安装的,另一个是从apt管理器安装的。


louis@louis:~$ node -v
v5.10.0

This returns older version of nodejs that you installed, I recommend you to remove it. 这将返回您安装的旧版nodejs,我建议您将其删除。


louis@louis:~$ nodejs -v
v6.2.1

This returns the current version of nodejs installed, possibly you installed it using package manager, I remember in Ubuntu it comes by nodejs executable name. 这将返回已安装nodejs当前版本 ,可能是您使用包管理器安装它,我记得在Ubuntu它由nodejs可执行文件名来实现。

I suggest you to create link like this 我建议你创建这样的链接

sudo ln -s `which nodejs` /usr/bin/node

so it will be available using node command also. 所以它也可以使用node命令。

nodejs vs node on ubuntu 12.04 ubuntu 12.04上的nodejs vs node


louis@louis:~$ npm -v
3.8.3

This is just version of your npm program and has nothing to do with nodejs version. 这只是你的npm程序的版本,与nodejs版本无关。

Better solution 好的解决方案

Uninstall all versions that you have and install node using nvm to switch between old/new versions easily 卸载您拥有的所有版本并使用nvm安装nodenvm切换旧版本/新版本

To install or update nvm, you can use the install script using cURL: 要安装或更新nvm,可以使用cURL使用安装脚本:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash

or Wget: 或者Wget:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash

Usage 用法

To download, compile, and install the latest v5.0.x release of node, do this: 要下载,编译和安装最新的v5.0.x版节点,请执行以下操作:

nvm install 5.0

And then in any new shell just use the installed version: 然后在任何新的shell中只使用已安装的版本:

nvm use 5.0

https://github.com/creationix/nvm#install-script https://github.com/creationix/nvm#install-script

I assume you are using ubuntu. 我假设你使用的是ubuntu。 node and nodejs are the same tool, but node is the legacy version and nodejs the current development branch. nodenodejs是相同的工具,但node是遗留版本, nodejs是当前开发分支。

npm however is the package manager for node(js) . 然而, npmnode(js)的包管理器。

Here's a bit of helpful information to add to the discussion and which will hopefully help you out regarding node version clashes. 这里有一些有用的信息可以添加到讨论中,并希望能帮助您解决有关节点版本冲突的问题。

Adding the NodeJs version to your $PATH in your .bash_profile (or it may be called .bashrc or .bashconfig) file will ensure your node calls from the terminal will use the latest and not the legacy version. 将NodeJs版本添加到.bash_profile(或者可能称为.bashrc或.bashconfig)文件中的$ PATH将确保来自终端的节点调用将使用最新版本而不是旧版本。

Using NVM (Node Version Manager) will allow you to install and change node versions on the fly with 'nvm use 6.0.0' and is highly recommended as some NPM packages will break if using a node and npm version that isn't correct for certain npm packages in your node_modules dir. 使用NVM (节点版本管理器)将允许您使用'nvm use 6.0.0'动态安装和更改节点版本,强烈建议使用节点和npm版本不正确的某些NPM软件包将中断node_modules目录中的某些npm包。 You will also have to add NVM to your $PATH in this case, but it's easy enough to do with: 在这种情况下,您还必须将NVM添加到$ PATH,但这很容易做到:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

More details can be found in the link provided. 更多细节可以在提供的链接中找到。

The OP's question was answered, I know, but I think pointing the OP to a better solution is also a good idea. 我知道,OP的问题得到了回答,但我认为将OP指向更好的解决方案也是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM