如何在Ubuntu上安装特定版本的Node?

时间:2013-06-03 13:32:53

标签: node.js ubuntu ubuntu-12.04

我想在Ubuntu 12.04上安装NodeJS版本0.8.18。我尝试安装最新版本,然后使用nvm恢复到0.8.18,但是当我运行我的代码时,显然安装的软件包和两个版本(最新版本和0.8.18)存在问题。由于我不知道如何解决这个问题,我从Node安装中清理了机器,并考虑直接安装我感兴趣的版本(v0.8.18)。

15 个答案:

答案 0 :(得分:35)

Chris Lea在他的ppa回购中有0.8.23。

此软件包允许您向apt-get添加存储库:(您也可以手动执行此操作)

sudo apt-get install software-properties-common

添加Chris Lea的存储库:

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

更新apt-get:

sudo apt-get update

安装Node.js:

sudo apt-get install nodejs=0.8.23-1chl1~precise1

我认为(随意编辑)如果您只添加node.js-legacy,则版本号是可选的。如果您同时添加legacy和ppa / chris-lea / node.js,则很可能需要添加该版本。

答案 1 :(得分:34)

可以使用dpkg从nodejs官方发行版安装特定版本的nodejs。

例如,目前最新的4.x版本是4.2.4,但您可以安装以前的4.2.3版本。

curl -s -O https://deb.nodesource.com/node_4.x/pool/main/n/nodejs/nodejs_4.2.3-1nodesource1~trusty1_amd64.deb
sudo apt-get install rlwrap
sudo dpkg -i nodejs_4.2.3-1nodesource1~trusty1_amd64.deb

答案 2 :(得分:27)

n模块为我工作。

运行此代码以清除npm的缓存,安装n,并安装最新的稳定版Node:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

请参阅:http://www.hostingadvice.com/how-to/update-node-js-latest-version/
并且:https://www.npmjs.com/package/n

安装特定版本的节点:

sudo n 6.11.2

查看版本:

node -v

您可能需要重新启动

答案 3 :(得分:9)

试试这种方式。这对我有用。

  1. wget nodejs.org/dist/v0.10.36/node-v0.10.36-linux-x64.tar.gz(download file)

  2. 转到下载Node.js二进制文件的目录,然后运行命令,即 sudo tar -C / usr / local --strip-components 1 -xzf node-v0.10.36 -linux-x64.tar.gz 在“/ usr / local /".

  3. 中安装Node.js二进制包
  4. 您可以查看: -

    $ node -v
     v0.10.36 
    $ npm -v
     1.4.28
    

答案 4 :(得分:5)

版本0.10也适用于此ppa

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

使用以下命令安装nodejs:

apt-get install nodejs=0.10.25-1chl1~precise1

感谢我的朋友Julian Xhokaxhiu

答案 5 :(得分:5)

NVM(节点版本管理器)

在Ubuntu 17.10中测试:

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh
nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9

对于最新长期支持版本的特定情况(建议您选择):

nvm install --lts
nvm use --lts
npm --version
npm install --global vaca
vaca

由于必须为每个新shell进行采购,您可能需要将以下内容添加到.bashrc

f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then
  . "$f" &>'/dev/null'
  nvm use --lts &>'/dev/null'
fi

优点:

  • 允许您使用多个版本的Node而不使用sudo

  • 类似于Ruby RVM和Python Virtualenv,被广泛认为是Ruby和Python社区的最佳实践

  • 尽可能下载预编译的二进制文件,如果没有,则下载源代码并为您编译一个

答案 6 :(得分:3)

  

注意:您可以使用NVM软件在更多nodejs时尚道中执行此操作。   但是我在一台没有让我使用NVM的机器上遇到了问题。所以我   必须寻找替代方案; - )

您可以手动下载和安装。

转到nodejs>下载>其他版本 http://nodejs.org/dist/

选择您要查找的版本 http://nodejs.org/dist/v0.8.18/

选择与您的环境相对应的发行文件并下载(照顾32位/ 64位版本)。 示例:http://nodejs.org/dist/v0.8.18/node-v0.8.18-linux-x64.tar.gz

提取文件并按照README.md:

上的说明操作
  

构建:

     

先决条件(仅限Unix):

* Python 2.6 or 2.7
* GNU Make 3.81 or newer
* libexecinfo (FreeBSD and OpenBSD only)
     

的Unix / Macintosh的:

./configure
make
make install
     

如果您的python二进制文件位于非标准位置或具有   非标准名称,改为执行以下操作:

export PYTHON=/path/to/python
$PYTHON ./configure
make
make install
     

视窗:

vcbuild.bat
     

运行测试:

     

的Unix / Macintosh的:

make test
     

视窗:

vcbuild.bat test
     

构建文档:

make doc
     

阅读文档:

man doc/node.1

也许您希望(必须)将文件夹移动到更合适的位置,例如/usr/lib/nodejs/node-v0.8.18/,然后在/ usr / bin上创建一个Symbolic Lynk以获取对您的安装的访问权限任何地方。

sudo mv /extracted/folder/node-v0.8.18 /usr/lib/nodejs/node-v0.8.18
sudo ln -s /usr/lib/nodejs/node-v0.8.18/bin/node /usr/bin/node

如果你想在同一台机器上使用不同版本,你可以使用debian替代品。按照之前发布的相同方式继续下载第二个版本。例如最新版本。

http://nodejs.org/dist/latest/ - > http://nodejs.org/dist/latest/node-v0.10.28-linux-x64.tar.gz

移至您喜欢的目的地,与您要安装的其他版本相同。

sudo mv /extracted/folder/node-v0.10.28 /usr/lib/nodejs/node-v0.10.28

按照README.md文件的说明进行操作。然后更新备选方案,对于每个版本,您都有下载安装替代方案。

sudo update-alternatives    --install genname symlink  altern  priority  [--slave  genname  symlink altern]
          Add a group of alternatives  to  the  system.   genname  is  the
          generic  name  for  the  master link, symlink is the name of its
          symlink  in  the  alternatives  directory,  and  altern  is  the
          alternative being introduced for the master link.  The arguments
          after  --slave  are  the  generic  name,  symlink  name  in  the
          alternatives  directory  and alternative for a slave link.  Zero
          or more --slave options, each followed by three  arguments,  may
          be specified.

          If   the   master   symlink  specified  exists  already  in  the
          alternatives system’s records, the information supplied will  be
          added  as a new set of alternatives for the group.  Otherwise, a
          new group, set to  automatic  mode,  will  be  added  with  this
          information.   If  the group is in automatic mode, and the newly
          added alternatives’ priority is higher than any other  installed
          alternatives  for  this  group,  the symlinks will be updated to
          point to the newly added alternatives.

例如:

sudo update-alternatives --install /usr/bin/node node /usr/lib/nodejs/node-v0.10.28 0 --slave /usr/share/man/man1/node.1.gz node.1.gz /usr/lib/nodejs/node-v0.10.28/share/man/man1/node.1

然后,您可以使用update-alternatives --config node在计算机中安装的任意数量的版本中进行选择。

答案 7 :(得分:2)

仅供参考Chris Lea的回购中可用的版本目前为0.8.25

sudo apt-get install nodejs=0.8.25-2chl1~raring1

答案 8 :(得分:2)

仅供参考,根据nodejs github repo wiki中的this page,Chris Lea的PPA(在其他几个答案中提到)已被NodeSource发行版取代,作为安装nodejs的主要方式来自Ubuntu:

curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs

这支持最新的三个(在撰写本文时)UTSntu的LTS版本:10.04(清晰),12.04 LTS(精确)和14.04(可靠)。

我不确定这会有助于安装旧版本的nodejs,但我会把它放在这里以防万一它需要帮助其他需要安装未包含在其中的特定(较新)版本的nodejs的人发行版的存储库。

答案 9 :(得分:2)

要在Ubuntu中安装特定版本的nodejs,可以使用以下命令,只需指定并替换版本号即可,例如,node_12.x将获取最新的12。

curl https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get install nodejs

答案 10 :(得分:1)

假设您要安装 Node 10,

首先,下载并执行 Node.js 10.x 安装程序:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

这将为官方 Node.js 10.x 存储库添加一个源文件,获取签名密钥

安装程序完成后,您将需要安装(或升级)Node.js:

sudo apt install nodejs

答案 11 :(得分:0)

Node.js项目最近推出了一个新的稳定版本,版本为0.10.0 在Ubuntu 13x上使用以下命令 sudo apt-get install nodejs = 0.10.18-1chl1~raring1

答案 12 :(得分:0)

是的,它是一个重复的答案,但我坚持使用n模块安装特定版本(以下命令安装节点版本6.9.5)。

npm install -g  n
n 6.9.5

答案 13 :(得分:0)

使用以下命令以相同的顺序安装nvm .nvm代表节点版本管理器。

sudo apt-get update
sudo apt-get install build-essential checkinstall libssl-dev
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

如果上面的命令不起作用,请在-o-之后添加-k。它应该如下所示:

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

然后nvm ls-remote查看可用版本。 如果您得到N / A作为回报,请运行以下内容。

export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist

或者您也可以运行以下命令

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

然后nvm install #.#.#将#替换为版本(比如nvm 8.9.4) 最后nvm use #.#.#

答案 14 :(得分:0)

以下是debian可用版本的列表:https://github.com/nodesource/distributions/tree/master/deb

对于此示例,假设您要使用版本14(在撰写本文时为LTS)

我们可以download this script from github,执行它并安装所需节点的版本。出于安全考虑,在执行脚本之前先阅读脚本是个好主意。

curl -sL https://raw.githubusercontent.com/nodesource/distributions/master/deb/setup_14.x | bash
apt-get install -y nodejs # may or may not require sudo based on your setup 

我喜欢这种方法,因为它不需要像nvm这样的无关项来定位特定版本

如果要为其他发行版或体系结构进行构建,则可以在https://nodejs.org/dist/

中找到更多构建