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
nvm node_mirror <url>
For example:
nvm node_mirror https://npmmirror.com/mirrors/node/
Setting npm Mirror
nvm npm_mirror <url>
For example:
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.):
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node
Setting npm Mirror
Add the following line to your shell profile file:
export NVM_NPM_MIRROR=https://npmmirror.com/mirrors/npm
Applying the Changes
After adding these lines, apply the changes:
source ~/.bashrc # or ~/.zshrc, etc.
Recommended Mirrors
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/
- Node.js:
Tencent Cloud:
- Node.js:
https://mirrors.cloud.tencent.com/nodejs-release/
- Node.js:
Huawei Cloud:
- Node.js:
https://repo.huaweicloud.com/nodejs/
- npm:
https://repo.huaweicloud.com/repository/npm/
- Node.js:
Europe Region Mirrors
- NodeSource:
- Node.js:
https://deb.nodesource.com/node/
- Node.js:
Temporary Mirror Usage
If you want to use a mirror just for a single installation without changing your configuration:
For nvm-sh (Linux/macOS)
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:
- Check your internet connection
- Try a different mirror
- Verify the mirror URL is correct and up-to-date
Invalid Mirror URL
If NVM reports an invalid mirror URL:
- Make sure the URL ends with a trailing slash (
/
) if required - Verify the URL format (should be
http://
orhttps://
) - 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:
- Try using the official Node.js repository
- Wait a few hours for the mirror to synchronize
- 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:
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:
# 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:
- Install Node.js versions with improved download speeds
- Learn more about NVM usage
- Check the FAQ for common questions and issues