简体   繁体   English

安装了node.js ver 0.8但是node --version仍然显示以前的版本0.6.12

[英]Installed node.js ver 0.8 but node --version still shows previous version 0.6.12

I tried installing node ver 0.8 on my ubuntu 12.04.It already has a node ver 0.6.12.The installation went suceesfully but when i type in 我尝试在我的ubuntu 12.04上安装节点版本0.8。它已经有一个节点版本0.6.12。安装过程非常好但是当我输入时

node --version

it still shows previous version. 它仍然显示以前的版本。 i tried to remove previous version using sudo apt-get remove node but it says package node is not installed.But on trying node --version it shows 0.6.12 Why is it so?? 我尝试使用sudo apt-get remove节点删除以前的版本,但它说没有安装包节点。但是尝试节点--version它显示0.6.12为什么会这样?

The problem is, you need to replace the new location for node with the old in your PATH variable. 问题是,您需要将节点的新位置替换为PATH变量中的旧位置。 If you have an old manual install, find the old path to node by running echo $PATH . 如果您有旧的手动安装,请通过运行echo $PATH找到节点的旧路径。 Then run this command: 然后运行以下命令:

export PATH=${PATH%$OLD_NODE_PATH/bin*}$NEW_NODE_PATH/bin${PATH#$*OLD_NODE_PATH/bin}

Or if you are using an install from the apt-get repository, just run: 或者,如果您使用apt-get存储库中的安装,只需运行:

export PATH=$NEW_NODE_PATH/bin

And that should fix your problem. 这应该可以解决你的问题。 But there is a better way! 但有更好的方法! The best tool to manage your node.js environment is NVM . 管理node.js环境的最佳工具是NVM It exactly like RVM for ruby and similar to virtualenv for python, if you are familiar with those tools. 如果您熟悉这些工具,它就像Ruby的RVM和python的virtualenv类似。 It allows you to switch versions of node and download new ones extremely efficiently, and is easy to use. 它允许您切换节点的版本并非常有效地下载新节点,并且易于使用。 Download and install with: 下载并安装:

curl https://raw.github.com/creationix/nvm/master/install.sh | sh

Then add this line to your bash (assuming you are running a bash shell) where it will be loaded (I prefer .bash_login for the personal stuff although it is not loaded by default): 然后将这一行添加到你的bash中(假设你正在运行一个bash shell)它将被加载(我更喜欢.bash_login用于个人内容,尽管它默认没有加载):

[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh

Source your bash script or restart the terminal then enter this command: 获取您的bash脚本或重新启动终端然后输入以下命令:

nvm install 0.8.0 && nvm use 0.8.0

This should set you up just fine. 这应该让你很好。 Although not necessary, you should probably get rid of all the other node installs, for the sake of tidiness. 虽然没有必要,但为了整洁,您可能应该摆脱所有其他节点安装。 Check out their github page but to get you started here is a quick overview: 查看他们的github页面,但是为了让您从这里开始是一个快速概述:

nvm ls                   # list all installed versions of node
nvm ls-remote            # list all available versions of node
nvm install 0.9.8        # download and install node v0.9.8
nvm use 0.8.0            # switch current environment to use node v0.8.0
nvm alias default 0.8.0  # set 0.8.0 as default, you can use 'nvm use default' 
nvm deactivate           # use system install of node
nvm run default app.js   # run app.js with default node version

I had this issue until I followd the directions on https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager 我遇到了这个问题,直到我按照https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager上的说明进行操作

which included running: 其中包括运行:

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update

first. 第一。 Then running sudo apt-get install nodejs npm got me to 0.8.x 然后运行sudo apt-get install nodejs npm让我达到了0.8.x

Also see: http://apptob.org/ 另见: http//apptob.org/

Seem like you install nodejs package from Ubuntu repo and manually install node 0.8 after? 好像你从Ubuntu repo安装nodejs包并在之后手动安装0.8节点? Try remove nodejs package. 尝试删除nodejs包。

The way to get a more recent version of Node.js is to add a PPA (personal package archive) maintained by NodeSource. 获取更新版本的Node.js的方法是添加由NodeSource维护的PPA(个人包存档)。 This will probably have more up-to-date versions of Node.js than the official Ubuntu repositories. 这可能会有比官方Ubuntu存储库更新的Node.js版本。

First, you need to install the PPA in order to get access to its contents: 首先,您需要安装PPA才能访问其内容:

curl -sL https://deb.nodesource.com/setup | sudo bash -

The PPA will be added to your configuration and your local package cache will be updated automatically. PPA将添加到您的配置中,您的本地包缓存将自动更新。 After running the setup script from nodesource, you can install the Node.js package using the below command. 从nodesource运行安装脚本后,您可以使用以下命令安装Node.js包。

sudo apt-get install nodejs

You can check the node by using this command 您可以使用此命令检查节点

node -v

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

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