Node and npm (cnpm) installation and use
environment
Ubuntu 20.04
download
Official:https://nodejs.org/zh-cn/download
The official Node package contains npm, choose the one according to your computer Download the required package. What I need is Linux (x86), as follows:
After downloading, I get:node-v18.15.0-linux-x64.tar.xz
Compressed package
Install Node (includes npm)
Extractnode-v18.15.0-linux-x64.tar.xz
the compressed package to the /usr/local
directory
sudo tar -xvf node-v18.15.0-linux-x64.tar.xz -C /usr/local/
sudo mv node-v18.15.0-linux-x64 node
environment variables
In .bashrc or /etc/profile or /etc/bash.bashrc add:
#========== node&npm env ============#
export NODE_HOME=/usr/local/node
export PATH=$PATH:${NODE_HOME}/bin
After making the changes, remember to make the source effective!
Test verification
node --version
npm --version
The result is as shown below:
Install cnpm
Since it is very slow to directly use the official npm image in China, it is recommended to use the Taobao cnpm image and its command cnpm.
(Taobao CNPM mirror is a complete npmjs.org mirror, which can be used instead of the official NPM. The synchronization frequency is currently once every 10 minutes to ensure that it is synchronized with the official service as much as possible.)
# 安装cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com
# 查看版本
cnpm -v
As we said above, node comes with npm. npm is in the /usr/local/node/lib/node_modules
directory,
similarly, cnpm is also in /usr/local/node/lib/node_modules
under the directory, as shown below: