Install Node 6.9 on Ubuntu Zesty 17.04

2019-04-19 06:00发布

问题:

I want to install a newest version of NodeJS on Ubuntu Zesty 17.04. But whether using apt-get or trying to download it from nodesource ppa, I always have the version 4.7.2.

Apt-get

sudo apt-get update
sudo apt-get install nodejs npm

Node PPA

curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
sudo apt-get update
apt-get install nodejs npm

Result

$> node -v
v4.7.2

How can I get the version 6.9 of NodeJS ?

回答1:

I didn't succeed to install it via apt-get or nodesource ppa. However I solved the problem by installing Node manually by following these steps :

  1. Remove the old version sudo apt-get remove --purge node
  2. Download Node binaries from https://nodejs.org/en/
  3. Extract the archive where you want tar -xzf <ARCHIVE>.tar.gz -C <YOUR_FOLDER>
  4. Create a node symbolic link ln -sf <YOUR_FOLDER>/bin/node /usr/bin/node
  5. Create a nodejs symbolic link ln -sf <YOUR_FOLDER>/bin/node /usr/bin/nodejs

result :

radouane@roufid:$ node -v
v6.10.2

I hope it helps !



回答2:

Best way is to use n. It is a node module that helps you to update and switch between node versions easily.

npm install n --global

n list will list all node versions.

If you want to switch to new version 6.10.2 use command n 6.10.2



回答3:

To install the NodeJS any version

# you can replace number 6 with new version
curl -sL https://deb.nodesource.com/setup_6.x | sudo bash - 
sudo apt install nodejs
node -v