节点 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?

查看:9
本文介绍了节点 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'.

推荐答案

很可能旧的 Node 在新的 Node 之前在你的 PATH 中.你可以在你的 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(或其他路径,如果它安装在其他地方).您需要在 HOME 的 .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 中是否有正确的 Node 版本,请运行:

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 (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).

此时哪个节点应该返回/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天全站免登陆