npm仓库地址配置:
获取npm的配置信息:
sp@k8s:~/code/mongodb-dir$ npm get registry
https://registry.npmjs.org/
sp@k8s:~/code/mongodb-dir$ npm config list
; "user" config from /home/sp/.npmrc
https-proxy = "http://127.0.0.1:7890"
proxy = "http://127.0.0.1:7890"
registry = "https://registry.npmjs.org"
; node bin location = /usr/local/bin/node
; node version = v20.15.0
; npm local prefix = /home/sp/code/mongodb-dir
; npm version = 10.7.0
; cwd = /home/sp/code/mongodb-dir
; HOME = /home/sp
; Run `npm config ls -l` to show all defaults.
配置为其它地址: 要配置 npm 使用其他仓库,可以通过以下命令来修改 npm 的仓库地址:
1. 临时修改仓库地址
如果你只想在当前会话中临时使用不同的仓库地址,可以运行:
npm set registry <新的仓库地址>
例如,将 npm 的仓库设置为淘宝的镜像仓库:
npm set registry https://registry.npm.taobao.org
这将修改 npm 配置,指向指定的仓库地址,但仅对当前会话有效。
2. 永久修改仓库地址
要永久更改仓库地址,可以将配置写入到全局 .npmrc 文件中:
npm config set registry <新的仓库地址> --global
例如:
npm config set registry https://registry.npm.taobao.org --global
这样修改后,所有的 npm 命令都会使用新的仓库地址。
3. 直接编辑 .npmrc 文件
你也可以直接编辑 .npmrc 文件,来配置 npm 仓库地址。.npmrc 文件通常位于用户的 home 目录下(全局配置),或者项目根目录下(项目级配置)。
在文件中添加如下内容:
registry=https://registry.npm.taobao.org
这样,你就完成了仓库地址的修改。
恢复到默认仓库
如果需要恢复到 npm 默认的官方仓库地址,可以运行:
npm config delete registry
这会删除自定义的仓库配置,恢复为默认的 https://registry.npmjs.org/。
代理相关:
//npm设置proxy
npm config set proxy http://your-proxy-address:port
npm config set https-proxy http://your-proxy-address:port
//查看proxy:
npm config get proxy
npm config get https-proxy
//还报错,可以设置为非严格模式即可
npm config set strict-ssl false
