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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16898001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:42:30  来源:igfitidea点击:

How to install a specific version of Node on Ubuntu?

node.jsubuntun

提问by Masiar

I would like to install NodeJS version 0.8.18 on Ubuntu 12.04. I tried to install the newest version and then reverting to 0.8.18 by using nvm, but when I run my code apparently there is some problem with the packages installed and the two versions (latest and 0.8.18). Since I don't know how to solve that problem, I cleaned the machine from the Node installation and thought about installing directly the version I'm interested in (v0.8.18).

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

采纳答案by Pickels

Chris Lea has 0.8.23 in his ppa repo.

Chris Lea 在他的 ppa 仓库中有 0.8.23。

This package let you add a repository to apt-get: (You can also do this manually)

这个包让你向 apt-get 添加一个存储库:(你也可以手动执行此操作)

sudo apt-get install software-properties-common

Add Chris Lea's repository:

添加 Chris Lea 的存储库:

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

Update apt-get:

更新 apt-get:

sudo apt-get update

Install Node.js:

安装 Node.js:

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

I think (feel free to edit) the version number is optional if you only add node.js-legacy. If you add both legacy and ppa/chris-lea/node.js you most likely need to add the version.

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

回答by Rimian

The nmodule worked for me.

n模块对我有用。

Run this code to clear npm's cache, install n, and install the latest stable version of Node:

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

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

See: http://www.hostingadvice.com/how-to/update-node-js-latest-version/
And: https://www.npmjs.com/package/n

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

To install a specific version of node:

要安装特定版本的节点:

sudo n 6.11.2

sudo n 6.11.2

To check what version:

要检查什么版本:

node -v

node -v

You might need to restart

您可能需要重新启动

回答by ddumbugie

It is possible to install specific version of nodejs from nodejs official distribution with using dpkg.

可以使用dpkg.

For example, currently recent 4.x version is 4.2.4, but you can install previous 4.2.3 version.

例如,当前最新的 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

回答by vineet

Try this way. This worked me.

试试这个方法。这对我有用。

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

  2. Go to the directory where the Node.js binary was downloaded to, and then run command i.e, sudo tar -C /usr/local --strip-components 1 -xzf node-v0.10.36-linux-x64.tar.gzto install the Node.js binary package in “/usr/local/”.

  3. You can check:-

    $ node -v
     v0.10.36 
    $ npm -v
     1.4.28
    
  1. wget nodejs.org/dist/v0.10.36/node-v0.10.36-linux-x64.tar.gz(下载文件)

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

  3. 您可以检查:-

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

回答by bonaccorso.p

version 0.10 is also avaible with this ppa

0.10 版也可与此 ppa 一起使用

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

install nodejs with:

使用以下命令安装 nodejs:

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

Thanks to my friend Julian Xhokaxhiu

感谢我的朋友Julian Xhokaxhiu

回答by waldyrious

FYI, according to this pagein the wiki of the nodejs github repo, Chris Lea's PPA (mentioned in several other answers) has been superseded by the NodeSourcedistributions as the main way of installing nodejs from source in Ubuntu:

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

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

This is supported for the three latest (at the time of writing this) LTS versions of Ubuntu: 10.04 (lucid), 12.04 LTS (precise) and 14.04 (trusty).

Ubuntu 的三个最新(在撰写本文时)LTS 版本支持此功能:10.04 (lucid)、12.04 LTS (precise) 和 14.04 (trusty)。

I'm not sure this will help in installing an old version of nodejs, but I'm putting this here in case it helps others who needed to install a specific (newer) version of nodejs that isn't included in their distro's repositories.

我不确定这是否有助于安装旧版本的 nodejs,但我将它放在这里是为了帮助其他需要安装未包含在其发行版存储库中的特定(较新)nodejs 版本的人。

回答by darofar

NOTE:you can use NVM software to do this in a more nodejs fashionway. However i got issues in one machine that didn't let me use NVM. So i have to look for an alternative ;-)

注意:您可以使用 NVM 软件以更 nodejs 的方式执行此操作。但是,我在一台不允许我使用 NVM 的机器上遇到了问题。所以我必须寻找替代品;-)

You can manually download and install.

您可以手动下载并安装。

go to nodejs > download > other releases http://nodejs.org/dist/

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

choose the version you are looking for http://nodejs.org/dist/v0.8.18/

选择您正在寻找的版本 http://nodejs.org/dist/v0.8.18/

choose distro files corresponding your environmment and download (take care of 32bits/64bits version). Example: http://nodejs.org/dist/v0.8.18/node-v0.8.18-linux-x64.tar.gz

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

Extract files and follow instructions on README.md :

提取文件并按照 README.md 上的说明进行操作:

To build:

Prerequisites (Unix only):

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

Unix/Macintosh:

./configure
make
make install

If your python binary is in a non-standard location or has a non-standard name, run the following instead:

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

Windows:

vcbuild.bat

To run the tests:

Unix/Macintosh:

make test

Windows:

vcbuild.bat test

To build the documentation:

make doc

To read the documentation:

man doc/node.1

构建:

先决条件(仅限 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

Maybe you want to (must to) move the folder to a more apropiate place like /usr/lib/nodejs/node-v0.8.18/ then create a Symbolic Lynk on /usr/bin to get acces to your install from anywhere.

也许你想(必须)将文件夹移动到一个更合适的地方,比如 /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

And if you want different release in the same machine you can use debian alternatives. Proceed in the same way posted before to download a second release. For example the latest release.

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

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

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

Move to your favorite destination, the same of the rest of release you want to install.

移动到您最喜欢的目的地,与您要安装的其余版本相同。

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

Follow instructions of the README.md file. Then update the alternatives, for each release you have dowload install the alternative with.

按照 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.

for example:

例如:

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

Then you can use update-alternatives --config nodeto choose between any number of releases instaled in your machine.

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

回答by David JM Emmett

FYI the available version for raring in Chris Lea's repo is currently 0.8.25

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

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

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

回答by nilakantha singh deo

yes, its a duplicate answer but I insist using n module to install a specific version(following commands installs node version 6.9.5).

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

npm install -g  n
n 6.9.5

回答by nilakantha singh deo

Install nvm using the following commands in the same order.nvm stands for node version manager.

按照相同的顺序使用以下命令安装 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

In case the above command does not work add -k after -o- .It should be as below:

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

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

Then nvm ls-remoteto see the available versions. In case you get N/A in return,run the following.

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

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

alternatively you can run the following commands too

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

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

Then nvm install #.#.#replacing # by version(say nvm 8.9.4) finally nvm use #.#.#

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