Ubuntu - Installation and CNPM NodeJS

Ubuntu version information:

# lsb_release --all
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.3 LTS
Release:	18.04
Codename:	bionic

Installation NodeJS

Download NodeJS

Access https://nodejs.org/en/download/ , download Linux Binaries (x64) file.

Here Insert Picture Description

unzip files

After the download is complete, enter the directory where the file:

# cd /usr/local/tmp/
# ll
-rw-r--r--  1 root root 14453992 2月   2 21:47 node-v12.14.1-linux-x64.tar.xz

Unzip node-v12.14.1-linux-x64.tar.xzthe file:

# tar -xvJf node-v12.14.1-linux-x64.tar.xz
# ll
drwxr-xr-x  6 1001 1001     4096 1月   7 20:24 node-v12.14.1-linux-x64/
-rw-r--r--  1 root root 14453992 2月   2 21:47 node-v12.14.1-linux-x64.tar.xz

Use the version command to view NodeJS

The node-v12.14.1-linux-x64move to the /opt/directory:

# mv -i node-v12.14.1-linux-x64 /opt/
# ll /opt/
total 12
drwxr-xr-x  3 root root 4096 2月   2 23:03 ./
drwxr-xr-x 24 root root 4096 1月  23 16:16 ../
drwxr-xr-x  6 1001 1001 4096 1月   7 20:24 node-v12.14.1-linux-x64/

About /optDirectory, Reference: Linux software is installed where appropriate, explain directory

Enter the node-v12.14.1-linux-x64/bin/directory:

# cd node-v12.14.1-linux-x64/bin/
# ll
total 44568
drwxr-xr-x 2 1001 1001     4096 1月   7 20:24 ./
drwxr-xr-x 6 1001 1001     4096 1月   7 20:24 ../
-rwxr-xr-x 1 1001 1001 45626872 1月   7 20:24 node*
lrwxrwxrwx 1 1001 1001       38 1月   7 20:24 npm -> ../lib/node_modules/npm/bin/npm-cli.js*
lrwxrwxrwx 1 1001 1001       38 1月   7 20:24 npx -> ../lib/node_modules/npm/bin/npx-cli.js*

Use node -vthe command to view the Node version information:

# ./node -v
v12.14.1

Configuration environment variable

Edit /etc/profilethe file:

# vim /etc/profile

Add NodeJS environment variables:

# NodeJS
export NODE_JS_HOME=/opt/node-v12.14.1-linux-x64
export PATH=$NODE_JS_HOME/bin:$PATH

When finished, save and exit, execute /etc/profilefiles, to take effect:

# source /etc/profile

Now, you can use the command NodeJS provided directly in the other directory, without having to use an absolute path. For example, to view NodeJS version information:

# node -v
v12.14.1

Check the version information of NPM:

# npm -v
6.13.4

reference

under linux deployment nodejs (two ways)

Installation CNPM

Installation CNPM

Because NPM servers in foreign countries, the use of NPM installation is relatively slow. Thus, the mirror can be used instead to provide Taobao NPM.

Global installed CNPM ( Company npm ):

# npm install cnpm -g --registry=https://r.npm.taobao.org

After the installation is complete, the command line prompt:

/opt/node-v12.14.1-linux-x64/bin/cnpm -> /opt/node-v12.14.1-linux-x64/lib/node_modules/cnpm/bin/cnpm
+ [email protected]
added 686 packages from 944 contributors in 178.301s

Now, you can use cnpminstead of npmcommand.

Reference: CNPM

View version information

# cnpm -v
[email protected] (/opt/node-v12.14.1-linux-x64/lib/node_modules/cnpm/lib/parse_argv.js)
[email protected] (/opt/node-v12.14.1-linux-x64/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)
[email protected] (/opt/node-v12.14.1-linux-x64/bin/node)
[email protected] (/opt/node-v12.14.1-linux-x64/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/opt/node-v12.14.1-linux-x64 
linux x64 5.3.0-26-generic 
registry=https://r.npm.taobao.org

Comparison of the configuration information NPM and CNPM

npm configuration information:

# npm config list
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.13.4 node/v12.14.1 linux x64"

; node bin location = /opt/node-v12.14.1-linux-x64/bin/node
; cwd = /root
; HOME = /root
; "npm config ls -l" to show all defaults.

cnpm configuration information:

# cnpm config list
; cli configs
disturl = "https://npm.taobao.org/mirrors/node"
metrics-registry = "https://r.npm.taobao.org/"
registry = "https://r.npm.taobao.org/"
scope = ""
user-agent = "npm/6.13.7 node/v12.14.1 linux x64"
userconfig = "/root/.cnpmrc"

; node bin location = /opt/node-v12.14.1-linux-x64/bin/node
; cwd = /root
; HOME = /root
; "npm config ls -l" to show all defaults.

reference

cnpm

CNPM

Taobao NPM mirror

Published 55 original articles · won praise 0 · Views 3182

Guess you like

Origin blog.csdn.net/qq_29761395/article/details/104153258