wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Run bash
to restart terminal to make the execution path recognizable.
Set http proxy for nvm:
nvm proxy # Show current proxy
nvm proxy [url] # Set proxy in format: `http://<server>:<port>
List available Node.js versions:
nvm ls available
which would output like:
| CURRENT | LTS | OLD STABLE | OLD UNSTABLE |
|--------------|--------------|--------------|--------------|
| 20.1.0 | 18.16.0 | 0.12.18 | 0.11.16 |
| 20.0.0 | 18.15.0 | 0.12.17 | 0.11.15 |
| 19.9.0 | 18.14.2 | 0.12.16 | 0.11.14 |
...
| 18.9.1 | 16.15.0 | 0.12.1 | 0.9.12 |
| 18.9.0 | 16.14.2 | 0.12.0 | 0.9.11 |
| 18.8.0 | 16.14.1 | 0.10.48 | 0.9.10 |
This is a partial list. For a complete list, visit https://nodejs.org/download/release
Choose a recent LTS version of Node.js to install:
nvm install 18.16.0
nvm use 18.16.0
You may encountered an error when running:
npm install -g npm@latest
ERROR: npm v9.5.1 is known not to run on Node.js v18.16.0. You'll need to upgrade
to a newer Node.js version in order to use this version of npm. This version of
npm supports the following node versions: `^14.17.0 || ^16.13.0 || >=18.0.0`. You
can find the latest version at https://nodejs.org/.
This is caused by the Windows Paths issue. See the references below for more info.
Just remove all npm
and nodejs
related paths from user and system environment variables, and re-organize in the order below:
You need to put the npm
install path of user (C:\Users\***\AppData\Roaming\npm
) up to the nodejs
install path (C:\sw\nodejs
).
Use following commands to check your paths:
env
which nvm # C:\Users\***\AppData\Roaming\nvm\nvm
which node # C:\sw\nodejs
which npm # C:\Users\***\AppData\Roaming\nvm\nvm
Then restart the shell (PowerShell may prevent you, so try cmder), and run the following again:
npm install -g npm@latest
Use following command to set http proxy for npm:
npm config set proxy http://<server>:<port>
And remove use following commands:
npm config rm proxy
npm config rm https-proxy
# To check configs
npm config list
npm config get registry
npm config set registry https://registry.npmmirror.com
npm config get registry
nvm
(Node Version Manager) is a tool that allows you to easily install and manage multiple versions of node
(Node.js) on the same system. npm
(Node Package Manager) is the default package manager for Node.js and is used to install and manage packages (libraries and tools) for use in Node.js projects.
The relationship between these three tools is as follows:
nvm
is used to install and manage different versions ofnode
.- Each version of
node
comes with a specific version ofnpm
. npm
is used to install and manage packages for use in Node.js projects.
In summary, nvm
is used to manage node
versions, and each version of node
comes with a specific version of npm
, which is used to manage packages for Node.js projects.
References:
-
node.js - How can I update NodeJS and NPM to their latest versions? - Stack Overflow
-
How do I update Node.js? - Stack Overflow
-
Try the latest stable version of npm | npm Docs
-
node.js - Is there a way to make npm install (the command) to work behind proxy? - Stack Overflow
-
node.js - How to clear https proxy setting of NPM? - Stack Overflow
-
npm使用国内镜像加速的几种方法-腾讯云开发者社区-腾讯云
Quickly install npm module via proxy
More details for proxy config in different envs:
References: