1.Node 下载安装
下载网址:https://nodejs.org/dist/v20.9.0/node-v20.9.0-x64.msi
下载完毕点击安装包 然后一路默认选项 Next …
2.Node验证是否安装成功
npm -v
node -v
Microsoft Windows [版本 10.0.22631.2428](c) Microsoft Corporation。保留所有权利。
C:\Users\liuzhengquan.cn>npm -v
10.2.3
C:\Users\liuzhengquan.cn>node -v
v20.9.0
C:\Users\liuzhengquan.cn>
3.设置文件存放路径(可选操作,随意,不操作则会自动使用默认路径存储)
3.1 查看默认路径命令:
# 获取下载依赖包路径
npm config get prefix
# 获取缓存路径
npm config get cache
3.2 如果需要更改可以在其它磁盘找个位置,创建两个文件夹,公共下载依赖存储文件夹 和 缓存文件夹
3.3 更新默认设置node路径配置
Microsoft Windows [版本 10.0.22631.2428](c) Microsoft Corporation。保留所有权利。
C:\Users\liuzhengquan.cn>npm -v
10.1.0
C:\Users\liuzhengquan.cn>node -v
v20.9.0
C:\Users\liuzhengquan.cn>npm config set prefix="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global"
C:\Users\liuzhengquan.cn>npm config set cache="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache"
C:\Users\liuzhengquan.cn>npm config get cache
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache
C:\Users\liuzhengquan.cn>npm config get prefix
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global
C:\Users\liuzhengquan.cn>
4.配置更新修改环境变量
4.1 新建配置【系统】环境变量
4.2 编辑新增【系统】环境变量
4.3 校验配置是否成功
cmd 中执行任意 npm 依赖包 这里以 express 演示
npm install express -g
Microsoft Windows [版本 10.0.22631.2428](c) Microsoft Corporation。保留所有权利。
C:\Users\liuzhengquan.cn>npm -v
10.1.0
C:\Users\liuzhengquan.cn>node -v
v20.9.0
C:\Users\liuzhengquan.cn>npm config set prefix="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global"
C:\Users\liuzhengquan.cn>npm config set cache="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache"
C:\Users\liuzhengquan.cn>npm config get cache
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache
C:\Users\liuzhengquan.cn>npm config get prefix
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global
C:\Users\liuzhengquan.cn>npm install express -g
changed 62 packages in 9s
11 packages are looking for funding
run `npm fund` for details
C:\Users\liuzhengquan.cn>
5.配置修改镜像地址(可选择操作,随意,如果嫌默认国外官方镜像太慢,可以修改为国内淘宝镜像地址)
5.1 查看默认镜像地址命令:
npm config get registry
Microsoft Windows [版本 10.0.22631.2428](c) Microsoft Corporation。保留所有权利。
C:\Users\liuzhengquan.cn>npm -v
10.1.0
C:\Users\liuzhengquan.cn>node -v
v20.9.0
C:\Users\liuzhengquan.cn>npm config set prefix="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global"
C:\Users\liuzhengquan.cn>npm config set cache="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache"
C:\Users\liuzhengquan.cn>npm config get cache
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache
C:\Users\liuzhengquan.cn>npm config get prefix
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global
C:\Users\liuzhengquan.cn>npm install express -g
changed 62 packages in 9s
11 packages are looking for funding
run `npm fund` for details
C:\Users\liuzhengquan.cn>npm config get registry
https://registry.npmjs.org/
C:\Users\liuzhengquan.cn>
5.2 修改默认官方镜像地址:
npm config set registry https://registry.npm.taobao.org
Microsoft Windows [版本 10.0.22631.2428](c) Microsoft Corporation。保留所有权利。
C:\Users\liuzhengquan.cn>npm -v
10.1.0
C:\Users\liuzhengquan.cn>node -v
v20.9.0
C:\Users\liuzhengquan.cn>npm config set prefix="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global"
C:\Users\liuzhengquan.cn>npm config set cache="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache"
C:\Users\liuzhengquan.cn>npm config get cache
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache
C:\Users\liuzhengquan.cn>npm config get prefix
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global
C:\Users\liuzhengquan.cn>npm install express -g
changed 62 packages in 9s
11 packages are looking for funding
run `npm fund` for details
C:\Users\liuzhengquan.cn>npm config get registry
https://registry.npmjs.org/
C:\Users\liuzhengquan.cn>npm config set registry https://registry.npm.taobao.org
C:\Users\liuzhengquan.cn>npm config get registry
https://registry.npm.taobao.org
C:\Users\liuzhengquan.cn>
5.3 如何还原官方镜像地址:
npm config set registry https://registry.npmjs.org/
Microsoft Windows [版本 10.0.22631.2428](c) Microsoft Corporation。保留所有权利。
C:\Users\liuzhengquan.cn>npm -v
10.1.0
C:\Users\liuzhengquan.cn>node -v
v20.9.0
C:\Users\liuzhengquan.cn>npm config set prefix="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global"
C:\Users\liuzhengquan.cn>npm config set cache="C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache"
C:\Users\liuzhengquan.cn>npm config get cache
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\cache
C:\Users\liuzhengquan.cn>npm config get prefix
C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global
C:\Users\liuzhengquan.cn>npm install express -g
changed 62 packages in 9s
11 packages are looking for funding
run `npm fund` for details
C:\Users\liuzhengquan.cn>npm config get registry
https://registry.npmjs.org/
C:\Users\liuzhengquan.cn>npm config set registry https://registry.npm.taobao.org
C:\Users\liuzhengquan.cn>npm config get registry
https://registry.npm.taobao.org
C:\Users\liuzhengquan.cn>npm config set registry https://registry.npmjs.org/
C:\Users\liuzhengquan.cn>npm config get registry
https://registry.npmjs.org/
C:\Users\liuzhengquan.cn>
5.4 安装 cnpm (主要是为了区分国内镜像和国外官方镜像,毕竟直接修改默认地址有点不太好,不过各位随意,哈哈哈…)
npm install -g cnpm
5.4.1 查看是否安装成功cnpm
cnpm -v
Microsoft Windows [版本 10.0.22631.2428](c) Microsoft Corporation。保留所有权利。
C:\Users\liuzhengquan.cn>npm install -g cnpm
npm WARN deprecated @npmcli/[email protected]: This functionality has been moved to @npmcli/fs
changed 457 packages in 8s
54 packages are looking for funding
run `npm fund` for details
C:\Users\liuzhengquan.cn>cnpm -v
[email protected] (C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global\node_modules\cnpm\lib\parse_argv.js)
[email protected] (C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global\node_modules\cnpm\node_modules\npm\index.js)
[email protected] (C:\Program_Files\Node\x64\20.9.0\node.exe)
[email protected] (C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global\node_modules\cnpm\node_modules\npminstall\lib\index.js)
prefix=C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global
win32 x64 10.0.22631
registry=https://registry.npmmirror.com
C:\Users\liuzhengquan.cn>
5.4.2 查看 cnpm 默认镜像地址:
cnpm config get registry
Microsoft Windows [版本 10.0.22631.2428](c) Microsoft Corporation。保留所有权利。
C:\Users\liuzhengquan.cn>npm install -g cnpm
npm WARN deprecated @npmcli/[email protected]: This functionality has been moved to @npmcli/fs
changed 457 packages in 8s
54 packages are looking for funding
run `npm fund` for details
C:\Users\liuzhengquan.cn>cnpm -v
[email protected] (C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global\node_modules\cnpm\lib\parse_argv.js)
[email protected] (C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global\node_modules\cnpm\node_modules\npm\index.js)
[email protected] (C:\Program_Files\Node\x64\20.9.0\node.exe)
[email protected] (C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global\node_modules\cnpm\node_modules\npminstall\lib\index.js)
prefix=C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global
win32 x64 10.0.22631
registry=https://registry.npmmirror.com
C:\Users\liuzhengquan.cn>cnpm config get registry
https://registry.npmmirror.com/
C:\Users\liuzhengquan.cn>
5.4.3 配置 cnpm 镜像地址:
cnpm config set registry https://registry.npm.taobao.org
Microsoft Windows [版本 10.0.22631.2428](c) Microsoft Corporation。保留所有权利。
C:\Users\liuzhengquan.cn>npm install -g cnpm
npm WARN deprecated @npmcli/[email protected]: This functionality has been moved to @npmcli/fs
changed 457 packages in 8s
54 packages are looking for funding
run `npm fund` for details
C:\Users\liuzhengquan.cn>cnpm -v
[email protected] (C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global\node_modules\cnpm\lib\parse_argv.js)
[email protected] (C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global\node_modules\cnpm\node_modules\npm\index.js)
[email protected] (C:\Program_Files\Node\x64\20.9.0\node.exe)
[email protected] (C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global\node_modules\cnpm\node_modules\npminstall\lib\index.js)
prefix=C:\Program_Files\Environment_Dependency_Cache_Package\Node\Repository\global
win32 x64 10.0.22631
registry=https://registry.npmmirror.com
C:\Users\liuzhengquan.cn>cnpm config get registry
https://registry.npmmirror.com/
C:\Users\liuzhengquan.cn>cnpm config set registry https://registry.npm.taobao.org
C:\Users\liuzhengquan.cn>cnpm config get registry
https://registry.npm.taobao.org/
C:\Users\liuzhengquan.cn>
5.4.4 如何使用cnpm
# cnpm install 需要下载的依赖包名称# 比如# npm install express -g 改使用cnpm 国内镜像则为这样 cnpm install express -g
6.npm / cnpm 常用命令参考指南大全
6.1 下载安装全局包
npm install -g <package_name>
6.2 卸载本地包
6.2.1 无作用域包
npm uninstall <package_name>
6.2.2 有作用域包
npm uninstall <@scope/package_name>
6.3 卸载全局包
6.3.1 无作用域包
npm uninstall -g <package_name>
6.3.2 有作用域包
npm uninstall -g <@scope/package_name>
6.4 更新依赖包 (本人觉得没必要,因为直接卸载再下载安装更有灵魂,有需要的自己度娘…)
版权归原作者 liuzhengquancn 所有, 如有侵权,请联系我们删除。