由于在学习配置时,网上的教程比较杂乱,用时很久才做好一些基础配置,把流程记录一下方便和我一样的小白学习
本文写于2023.2.25,如果间隔太久,下述内容可能会失效,请另寻教程
下载 Node.js 安装程序。可以从 Node.js 官网下载适用于 Windows 的 Node.js LTS安装程序(https://nodejs.org/en/download/)。
运行 Node.js 安装程序并按照提示安装 Node.js。(一直下一步)
安装完成后,打开命令提示符或 PowerShell 终端窗口(按下 Win+R,键入 "cmd" 或 "powershell" 并按 Enter 键)。
在终端窗口中输入以下命令以确认是否已安装 npm:
shellnpm -v
# v18.14.2
如果已成功安装 npm,则将显示 npm 的版本号。
如果未安装 npm,则需要安装。可以使用以下命令在命令提示符或 PowerShell 终端窗口中安装 npm:
shellnpm install npm@latest -g
此命令将在全局范围内安装最新版本的 npm。
等待安装完成后,可以在命令提示符或 PowerShell 终端窗口中输入以下命令来验证 npm 是否已成功安装:
shellnpm -v
# 9.5.0
如果 npm 成功安装,则将显示 npm 的版本号。
现在已经成功安装了 npm。请注意,如果使用的是 Windows 10 的某些版本,则可能需要在安装 npm 时使用管理员权限。
npm的两个配置文件夹node_cache
和node_global
默认存放在C盘,可以手动进行更改
在想要的位置新建两个文件夹,命名为node_cache
和node_global
,例如我存放在D:\Software\Develop Tool\Nodejs\configuration
中
打开cmd,配置路径
shnpm config set prefix "D:\Software\Develop Tool\Nodejs\configuration\node_global"
npm config set cache "D:\Software\Develop Tool\Nodejs\configuration\node_cache"
shell# 部分config命令
npm config ls # 查看简单的配置项
npm config ls -l # 查看所有配置项
npm config get cache # 查看缓存配置,get后面可以跟任意配置项
npm config edit # 直接编辑config文件,这个会打开文本
npm info underscore # 检测镜像源
配置环境变量
系统变量:新建变量名:NODE_PATH 变量值:node_global文件夹下的node_modules文件夹。我的是:D:\Software\Develop Tool\Nodejs\configuration\node_global\node_modules
用户变量:将Path变量中默认的npm路径修改为新建的node_global路径:D:\Software\Develop Tool\Nodejs\configuration\node_global
测试并配置淘宝源
shellnpm config set registry https://registry.npm.taobao.org # 全局切换淘宝源 npm config set registry https://registry.npmjs.org/ # 全局切换官方源
本文作者:southyang
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!