Skip to content

Configuring Mirrors for NVM

When using NVM to install Node.js, you might encounter slow download speeds, especially in certain geographic regions. Configuring mirrors can significantly improve download speeds by using servers that are closer to your location.

Why Use Mirrors?

  • Faster downloads: Mirrors located closer to you can provide better download speeds
  • Improved reliability: Alternative mirrors can help when the official servers are experiencing issues
  • Bypass network restrictions: Some networks might have restrictions accessing certain domains

Mirror Configuration for Windows (nvm-windows)

NVM for Windows provides commands to set mirrors for both Node.js and npm downloads.

Setting Node.js Mirror

bash
nvm node_mirror <url>

For example:

bash
nvm node_mirror https://npmmirror.com/mirrors/node/

Setting npm Mirror

bash
nvm npm_mirror <url>

For example:

bash
nvm npm_mirror https://npmmirror.com/mirrors/npm/

Verifying Mirror Settings

The mirror settings are stored in the settings.txt file in your NVM installation directory, typically at:

C:\Users\<username>\AppData\Roaming\nvm\settings.txt

You can check this file to verify your mirror settings:

root: C:\Users\<username>\AppData\Roaming\nvm
path: C:\Program Files\nodejs
node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/

Mirror Configuration for Linux/macOS (nvm-sh)

For nvm-sh on Linux and macOS, you can set mirrors using environment variables in your shell profile file.

Setting Node.js Mirror

Add the following line to your shell profile file (~/.bashrc, ~/.zshrc, etc.):

bash
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node

Setting npm Mirror

Add the following line to your shell profile file:

bash
export NVM_NPM_MIRROR=https://npmmirror.com/mirrors/npm

Applying the Changes

After adding these lines, apply the changes:

bash
source ~/.bashrc  # or ~/.zshrc, etc.

Here are some popular mirrors you can use:

Global Mirrors

  • Official Node.js: https://nodejs.org/dist
  • Official npm: https://registry.npmjs.org

China Region Mirrors

  • npmmirror (formerly CNPM):

    • Node.js: https://npmmirror.com/mirrors/node/
    • npm: https://npmmirror.com/mirrors/npm/
  • Tencent Cloud:

    • Node.js: https://mirrors.cloud.tencent.com/nodejs-release/
  • Huawei Cloud:

    • Node.js: https://repo.huaweicloud.com/nodejs/
    • npm: https://repo.huaweicloud.com/repository/npm/

Europe Region Mirrors

  • NodeSource:
    • Node.js: https://deb.nodesource.com/node/

Temporary Mirror Usage

If you want to use a mirror just for a single installation without changing your configuration:

For nvm-sh (Linux/macOS)

bash
NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node nvm install 18.16.0

Troubleshooting Mirror Issues

Mirror Connection Timeout

If you experience timeouts when connecting to a mirror:

  1. Check your internet connection
  2. Try a different mirror
  3. Verify the mirror URL is correct and up-to-date

Invalid Mirror URL

If NVM reports an invalid mirror URL:

  1. Make sure the URL ends with a trailing slash (/) if required
  2. Verify the URL format (should be http:// or https://)
  3. Check if the mirror is still operational

Mirror Synchronization Issues

Mirrors might not be immediately synchronized with the official repositories. If you can't find a very recent Node.js version:

  1. Try using the official Node.js repository
  2. Wait a few hours for the mirror to synchronize
  3. Try a different mirror that might be updated more frequently

Restoring Default Mirrors

Windows (nvm-windows)

To restore the default mirrors, set them back to the official URLs:

bash
nvm node_mirror https://nodejs.org/dist/
nvm npm_mirror https://github.com/npm/cli/archive/

Linux/macOS (nvm-sh)

To restore the default mirrors, remove the environment variables from your shell profile file and source it again:

bash
# Remove these lines from your ~/.bashrc or ~/.zshrc
# export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node
# export NVM_NPM_MIRROR=https://npmmirror.com/mirrors/npm

# Then source your profile file
source ~/.bashrc  # or ~/.zshrc, etc.

Next Steps

After configuring mirrors, you can proceed to:

Built with VitePress