Simple way to install node.js on ubuntu

1. Installation

1.$ sudo apt - get install nodejs 

2.$ sudo apt - get install npm

Second, upgrade

    1. The upgrade npm command is as follows:

$ sudo npm install npm -g
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
[email protected] /usr/local/lib/node_modules/npm
2. Upgrade the node.js command as follows: 
$ npm install –gn $ n latest (upgrade node.js to the latest version) or $ n stable (upgrade node.js to the latest stable version)

    The version number can also be followed by n such as: $ n v0.10.26or $n 0.10.26

3. Replace the npm image with the Taobao image

 

1. Get the original mirror address

$ npm get registry 

> https://registry.npmjs.org/

set to Taobao

$ npm config set registry http://registry.npm.taobao.org/

2. Replace with the original

$ npm config set registry https://registry.npmjs.org/

 

Fourth, optional cnpm

1. Description: Because the npm installation plugin is downloaded from a foreign server, it is greatly affected by the network and may be abnormal. It would be fine if the npm server was in China, so the Taobao team we are happy to share did this. ! From the official website: "This is a complete npmjs.org mirror. You can use this instead of the official version (read-only). The synchronization frequency is currently every 10 minutes to ensure that it is synchronized with the official service as much as possible.";

2. Official website: http://npm.taobao.org ;

3. Installation: command prompt execution npm install cnpm -g --registry=https://registry.npm.taobao.org; Note: After installation, it is best to check its version number cnpm -v or close the command prompt and reopen it, there may be errors when using it directly after installation;

Note: The usage of cnpm is exactly the same as that of npm, except that npm is changed to cnpm when executing the command (the following operations will use cnpm instead of npm)

Five, global installation and local installation

  The package installation of npm is divided into two types: local installation (local) and global installation (global). From the point of view of the command line, the only difference is whether there is -g or not.

   For example, we use the npm command to install the commonly used Node.js web framework module  express:

$ npm install express           # local installation  $ npm install express - g # global installation 

6. Uninstall
1. Uninstall npm first
sudo npm uninstall npm -g
2. Uninstall nodejs
sudo apt-get remove nodejs
Method 2: nvm installation

Install

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

use

After the installation is successful, you need to close xshell and restart it. nvm will take effect.

Use to command -v nvmsee if nvm is installed successfully

root@linuxidc:~# command -v nvm
nvm

View installed

By nvm lslooking at the installed version

$ nvm ls
            N/A
node -> stable (-> N/A) (default) iojs -> N/A (default)

See what's available for installation

By nvm ls-remoteviewing the available version

$ nvm ls-remote
        v0.1.14 v0.1.15 v0.1.16 v0.1.17 v0.1.18 ...

install nodejs

Install through nvm install 7.8.0, and we can choose the version number that follows.

root@linuxidc:~# nvm install 7.8.0
Downloading and installing node v6.2.0...
Downloading https://nodejs.org/dist/v7.8.0/node-v7.8.0-linux-x64.tar.xz...

We are using a foreign server to download, very slow, wait patiently, nodejs and nvm are successfully installed!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325112371&siteId=291194637