How to install a specific version of Node on Ubunt

2019-01-16 07:56发布

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

12条回答
何必那么认真
2楼-- · 2019-01-16 08:27

NVM (Node Version manager)

Tested in 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

For the particular case of the most recent long term support version (recommended if you can choose):

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

Since the sourcing has to be done for every new shell, you will probably want to add the following to your .bashrc:

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

Advantages:

  • allows you to use multiple versions of Node and without sudo

  • is analogous to Ruby RVM and Python Virtualenv, widely considered best practice in Ruby and Python communities

  • downloads a pre-compiled binary where possible, and if not it downloads the source and compiles one for you

查看更多
Ridiculous、
3楼-- · 2019-01-16 08:34

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

npm install -g  n
n 6.9.5
查看更多
放荡不羁爱自由
4楼-- · 2019-01-16 08:36

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

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

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.

查看更多
Anthone
5楼-- · 2019-01-16 08:37

Chris Lea has 0.8.23 in his ppa repo.

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

sudo apt-get install software-properties-common

Add Chris Lea's repository:

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

Update apt-get:

sudo apt-get update

Install 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.

查看更多
趁早两清
6楼-- · 2019-01-16 08:40

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

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

查看更多
爷的心禁止访问
7楼-- · 2019-01-16 08:41

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

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:

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

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

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 #.#.#

查看更多
登录 后发表回答