节点5.5.0已经安装,但是节点-v获取了"v4.2.1".在OS X&家酿? [英] node 5.5.0 already installed but node -v fetches with "v4.2.1" on OS X & homebrew?

查看:58
本文介绍了节点5.5.0已经安装,但是节点-v获取了"v4.2.1".在OS X&家酿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的nodejs v4.2.1更新到最新版本,并成功地获得了它.但是node -v仍然给我'-v4.2.1'.

I'm trying to update my nodejs v4.2.1 to the latest version and successfully got that. But node -v still gives me '-v4.2.1'.

推荐答案

在您的PATH中,较旧的Node可能早于较新的Node. 您可以在shell中运行:

Probably the older Node is in your PATH before the newer one. You can run in your shell:

which node

查看默认运行的Node二进制文件在哪里(在您的情况下为v4.2.1).您可以通过运行以下命令查看PATH是什么:

to see where is the Node binary that is run by default (v4.2.1 in your case). You can see what is your PATH by running:

echo $PATH

它将显示如下内容:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

这些是在您每次键入"node"或任何其他命令时按顺序搜索的目录.如果PATH没有安装新节点的目录,或者位于旧节点的目录之后,则新节点将不会运行.解决该问题可能只需运行以下命令即可:

Those are directories that are searched in order whenever you type "node" or any other command. If your PATH doesn't have the directory where you have your new Node installed, or if it is after the directory where you have your old Node, then the new Node will not be run. Fixing the problem may be as simple as running:

PATH="/usr/local/bin:$PATH"

(如果新节点安装在/usr/local/bin中)(如果安装在其他位置,则使用其他路径).您需要在首页的.profile.bashrc中添加此行,以便在每次登录时启动新Shell时正确设置PATH.

if your new Node is installed in /usr/local/bin (or with some other path if it is installed somewhere else). You need to add this line in .profile or .bashrc in your HOME to have the PATH set up correctly every time you log in start a new shell.

要查看您在/usr/local/bin中是否具有正确的节点版本,请运行:

To see if you have the correct Node version in /usr/local/bin run:

/usr/local/bin/node -v

更新

看看您的评论和更新的答案,我敢打赌,您是手动安装了Node 4.2.1(不适用于brew),并且brew无法更新/usr/local/bin中的二进制文件.

Update

Looking at your comment and updated answer my bet would be that you have installed Node 4.2.1 manually (not with brew) and now brew doesn't update the binary in /usr/local/bin.

我建议手动安装并控制版本.我将向您展示用于下载源代码,配置,构建和安装在版本目录中以及更新PATH的命令.

What I would recommend is to install it manually and have control over the versions. I'll show you the commands to download the source, configure, build and install in a versioned directory, and update the PATH.

根据节点下载页面,当前版本为v6.1.0,但如果您愿意特别是5.5.0或任何其他版本(最新的5.x是v5.9.1),然后只需将以下命令更改为所需的版本即可. (所有版本均在此处中列出.)

According to the Node download page the current version is v6.1.0 but if you want specifically 5.5.0 or any other version (the latest 5.x is v5.9.1) then just change the commands below to the verson that you want. (All versions are listed here.)

# change dir to your home:
cd ~
# download the source:
curl -O https://nodejs.org/dist/v6.1.0/node-v6.1.0.tar.gz
# extract the archive:
tar xzvf node-v6.1.0.tar.gz
# go into the extracted dir:
cd node-v6.1.0
# configure for installation:
./configure --prefix=/opt/node-v6.1.0
# build and test:
make && make test
# install:
sudo make install
# make a symlink to that version:
sudo ln -svf /opt/node-v6.1.0 /opt/node

,最后将PATH="/opt/node/bin:$PATH"添加到您的.profile.bashrc(可以删除或保留HOME中的node-v6.1.0目录和.tar.gz以便以后使用).

and finally add PATH="/opt/node/bin:$PATH" to your .profile or .bashrc (The node-v6.1.0 directory in your HOME and the .tar.gz can be removed or kept for later use).

此时,which node应该返回/opt/node/bin/node,并且版本是您想要的版本(在本示例中为6.1.0).如果要测试另一个版本,则将其安装在/opt/node-vXXX下的另一个目录中,并更新符号链接.您不必更新PATH,只需更新符号链接即可.

At this point which node should return /opt/node/bin/node and the version is the one that you want (6.1.0 in this example). If you want to test another version then install it in another directory under /opt/node-vXXX and update the symlink. You won't have to update PATH, just the symlink.

这比使用brew做更多的工作,但是您完全可以控制安装的内容和安装位置.我对这种解决方案的满意之处在于,您的版本永远不会混淆或混淆,您可以随时安装/删除版本,并迅速将任何版本设置为默认版本.

This is more work than with brew but you have total control over what gets installed and where. What I like about this solution is that your versions never get mixed or confused and you can install/remove versions any time and quickly set any version as default.

这篇关于节点5.5.0已经安装,但是节点-v获取了"v4.2.1".在OS X&家酿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆