Linux下node安装
下载:https://nodejs.org/zh-cn/download/
[root@localhost ~]# mkdir -p /usr/local/lib/nodejs
[root@localhost ~]# tar -zxvf node-v14.17.4-linux-x64.tar.gz -C /usr/local/lib/nodejs
# 添加环境变量
[root@localhost ~]# vi /etc/profile
......
export PATH=$PATH:/usr/local/lib/nodejs/node-v14.17.4-linux-x64/bin
[root@localhost ~]# source /etc/profile
[root@localhost ~]# node -v
v14.17.4
[root@localhost ~]# npm version
{
npm: '6.14.14',
ares: '1.17.1',
brotli: '1.0.9',
cldr: '39.0',
icu: '69.1',
llhttp: '2.1.3',
modules: '83',
napi: '8',
nghttp2: '1.42.0',
node: '14.17.4',
openssl: '1.1.1k',
tz: '2021a',
unicode: '13.0',
uv: '1.41.0',
v8: '8.4.371.23-node.76',
zlib: '1.2.11'
}
[root@localhost ~]# npx -v
6.14.14
我们通过测试来说明npm config set registry
和项目根目录下.npmrc
优先级。
首先,创建项目,进入项目根目录,创建配置文件.npmrc
,设置registry
为https://registry.npm.taobao.org/
。
[root@localhost ~]# mkdir test_node
[root@localhost ~]# cd test_node/
[root@localhost test_node]# vi .npmrc
registry=https://registry.npm.taobao.org/
然后,在执行时使用npm config set registry
再次设置,通过npm config get registry
查看当前npm仓库。
[root@localhost test_node]# npm config set registry https://registry.cnpmjs.org && npm config get registry
https://registry.npm.taobao.org/
可以看出来,当前npm仓库为.npmrc
中配置的地址,即项目根目录下.npmrc
优先级高于npm config set registry
。