我想在Ubuntu 12.04上安装NodeJS版本0.8.18。我尝试安装最新版本,然后使用nvm
恢复到0.8.18,但是当我运行我的代码时,显然安装的软件包和两个版本(最新版本和0.8.18)存在一些问题。由于我不知道如何解决这个问题,我从Node安装中清理了机器,并考虑直接安装我感兴趣的版本(v0.8.18)。
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,则很可能需要添加该版本。
Node.js项目最近用0.10.0发布推出了一个新的稳定版本在Ubuntu 13x上使用以下命令sudo apt-get install nodejs = 0.10.18-1chl1~raring1
是的,它是一个重复的答案,但我坚持使用n模块安装特定版本(以下命令安装节点版本6.9.5)。
npm install -g n
n 6.9.5
使用以下命令以相同的顺序安装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 #.#.#
可以使用dpkg
从nodejs官方发行版安装特定版本的nodejs。
cat /etc/lsb-release
。uname -m
的架构。nodejs-dbg
或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
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
您可能需要重新启动
试试这种方式。这对我有用。
$ node -v
v0.10.36
$ npm -v
1.4.28
在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
好处:
此ppa也提供0.10版本
apt-add-repository ppa:chris-lea/node.js
安装nodejs:
apt-get install nodejs=0.10.25-1chl1~precise1
感谢我的朋友Julian Xhokaxhiu
注意:您可以使用NVM软件在更多nodejs时尚中执行此操作。但是我在一台没有让我使用NVM的机器上遇到了问题。所以我必须寻找替代方案;-)
您可以手动下载和安装。
转到nodejs>下载>其他版本http://nodejs.org/dist/
选择你要找的版本http://nodejs.org/dist/v0.8.18/
选择与您的环境相对应的发行文件并下载(照顾32位/ 64位版本)。示例:qazxsw poi
提取文件并按照README.md上的说明操作:
To build:
先决条件(仅限Unix):
http://nodejs.org/dist/v0.8.18/node-v0.8.18-linux-x64.tar.gzUNIX / Macintosh的:
* Python 2.6 or 2.7 * GNU Make 3.81 or newer * libexecinfo (FreeBSD and OpenBSD only)
如果您的python二进制文件位于非标准位置或具有非标准名称,请运行以下命令:
./configure make make install
视窗:
export PYTHON=/path/to/python $PYTHON ./configure make make install
To run the tests:
UNIX / Macintosh的:
vcbuild.bat
视窗:
make test
To build the documentation:
vcbuild.bat test
To read the documentation:
make doc
也许你想(必须)将文件夹移动到更合适的位置,如/usr/lib/nodejs/node-v0.8.18/,然后在/ usr / bin上创建一个Symbolic Lynk,以便从任何地方访问您的安装。
man doc/node.1
如果你想在同一台机器上使用不同的版本,你可以使用debian替代品。按照之前发布的相同方式继续下载第二个版本。例如最新版本。
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
- > http://nodejs.org/dist/latest/
移动到您最喜欢的目的地,与您要安装的其余版本相同。
http://nodejs.org/dist/latest/node-v0.10.28-linux-x64.tar.gz
按照README.md文件的说明进行操作。然后更新备选方案,对于每个版本,您都有下载安装替代方案。
sudo mv /extracted/folder/node-v0.10.28 /usr/lib/nodejs/node-v0.10.28
例如:
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
在计算机中安装的任意数量的版本之间进行选择。
仅供参考,Chris Lea的回购可用版本目前为0.8.25
update-alternatives --config node
根据在nodejs github repo的wiki中的sudo apt-get install nodejs=0.8.25-2chl1~raring1
,根据this page在其他几个答案中提到的,它被NodeSource发行版取代,作为在Ubuntu中从源安装nodejs的主要方式:
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。