Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvm 设置下载 node 的镜像地址 #7

Open
xhlwill opened this issue Dec 22, 2016 · 7 comments
Open

nvm 设置下载 node 的镜像地址 #7

xhlwill opened this issue Dec 22, 2016 · 7 comments

Comments

@xhlwill
Copy link
Owner

xhlwill commented Dec 22, 2016

在 windows 上安装 nvm 后准备安装 node,输入 nvm install 6.9.2 后就一直点点点…
经验告诉我(不要问我经验是谁)等到最后还是安装失败(ಥ _ ಥ)

在命令行输入 nvm 能看到

λ nvm

Running version 1.1.1.

Usage:

  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm install <version> [arch] : The version can be a node.js version or "latest" for the latest stable version.
                                 Optionally specify whether to install the 32 or 64 bit version (defaults to system arch).
                                 Set [arch] to "all" to install 32 AND 64 bit versions.
  nvm list [available]         : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
  nvm on                       : Enable node.js version management.
  nvm off                      : Disable node.js version management.
  nvm proxy [url]              : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.
                                 Set [url] to "none" to remove the proxy.
  nvm node_mirror [url]        : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.
  nvm npm_mirror [url]         : Set the npm mirror. Defaults to https://github.com/npm/npm/archive/. Leave [url] blank to default url.
  nvm uninstall <version>      : The version must be a specific version.
  nvm use [version] [arch]     : Switch to use the specified version. Optionally specify 32/64bit architecture.
                                 nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode.
  nvm root [path]              : Set the directory where nvm should store different versions of node.js.
                                 If <path> is not set, the current root will be displayed.
  nvm version                  : Displays the current running version of nvm for Windows. Aliased as v.

nvm 下载 node 的地址用的是https://nodejs.org/dist/,下载 npm 的地址用的是https://github.com/npm/npm/archive/
这些镜像在国外,在国内由于众所周知的原因下载很慢,好在淘宝弄了一个镜像库,好开心,果断换上……不过马上就悲伤的发现nvm node_mirrornvm npm_mirror命令都不管用,我用的是 nvm-windows,不确定 mac 和 linux 上有没有问题,不过机智如我知道肯定有其他的解决办法
timg
:在 nvm 的安装路径下,找到 settings.txt,在后面加上这两行

node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

重启终端后再安装速度飞起,安装完成后就能看到所有和正在用的 node 版本了

λ nvm list

  * 6.9.2 (Currently using 64-bit executable)

这时候我兴高采烈地开始装东西了,输入

λ npm install -g weex-toolkit

出来血红的 ERR! 又让我傻眼了,尼玛不是设置了淘宝的镜像吗,怎么不管用啊……
9e47423d269759ee1ce833bbb6fb43166c22df47
且慢,前面设置的其实是安装 npm 的镜像,而现在是用 npm 去安装 package,所以得设置让 npm 知道去哪获取 package:

λ npm config set registry https://registry.npm.taobao.org

这时候再安装又可以飞起了。


Update: 呃,mac 和 linux 版 nvm 就没有 node_mirror & npm_mirror 命令 😂 ,设置下载 node 镜像地址的方式是

export NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist

将等号后面地址换成淘宝镜像(https://npm.taobao.org/mirrors/node)就可以了 😄 详见➡️

@xhlwill xhlwill added node and removed node/npm labels Jan 18, 2017
@xhlwill xhlwill changed the title nvm设置node的下载路径 nvm设置node的下载地址 Mar 22, 2017
@xhlwill xhlwill changed the title nvm设置node的下载地址 nvm 设置下载 node 的镜像地址 Apr 13, 2017
@NetworkBaby
Copy link

image
没换之前要1个小时,换了之后0.3s搞定,快得我以为出错了

@BadWaka
Copy link

BadWaka commented Aug 2, 2017

牛!

@mingzhou
Copy link

Good!!!

@soarpatriot
Copy link

顶顶顶!

@RomeoMo
Copy link

RomeoMo commented Jan 17, 2018

Good Job!

@sunyongjian
Copy link

设个临时的环境变量就可以了,非 windows

  • export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/
  • nvm install node

@popring
Copy link

popring commented Apr 13, 2021

如果嫌更换npm源麻烦,推荐用安装 nrm, 命令直接更换

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants