Install
wget https://nodejs.org/dist/v16.18.0/node-v16.18.0-linux-x64.tar.xz
xz -d node-v16.18.0-linux-x64.tar.xz
tar -xf node-v16.18.0-linux-x64.tar
# 下文更改全局目录用到
mkdir -p /matt/data/npm/global_modules
mkdir -p /matt/data/npm/cache
cat << EOF >> /etc/profile
export NODE_HOME=/root/node-v16.18.0-linux-x64
export NODE_MODULE_HOME=/matt/data/npm/global_modules/
export PATH=$NODE_HOME/bin:$NODE_MODULE_HOME/bin:$PATH
EOF
source /etc/profile
node -v
npm -v
npx -v
设置镜像
npm config set registry https://registry.npm.taobao.org
npm config get registry
全局目录
# 默认全局路径 <node_install_path>/lib/node_modules/npm/node_modules
/root/node-v16.18.0-linux-x64/lib/node_modules/npm/node_modules
# 修改路径,路径已在上文创建好
npm config set prefix "/matt/data/npm/global_modules"
npm config set cache "/matt/data/npm/cache"
# 查看
npm config get prefix
npm config get cache
npm --global cache verify
查看安装依赖
# 查看全局安装的包
npm list -g