Nvm 下载和 Node.js 环境配置

本文最后更新于 2025年8月14日 星期四 10:51

下载与安装

下载 nvm

Windows 前往 https://github.com/coreybutler/nvm-windows/releases 下载 nvm-setup.exe,并安装。

Linux 和 macOS 前往 https://github.com/nvm-sh/nvm#installing-and-updating 下载并安装,具体指令如下:

1
2
3
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# 或者使用 wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

使用 nvm 安装 Node.js

1
2
nvm install latest # Windows
nvm install stable # Linux/macOS

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
# 查看已安装的 Node.js 版本
nvm ls

# 切换版本
nvm use 24.4.1

# 查看当前版本​​
nvm -v
node -v
npm -v

# 更新npm
npm install -g npm@latest

全局包管理

1
2
3
4
5
6
7
8
9
10
11
# 查看全局安装的包
npm ls -g --depth=0

# 查看全局安装路径​​
npm root -g

# 检查全局包是否过时​​
npm outdated -g

# 卸载全局包​​
npm uninstall -g 包名

更新包

以 Hexo 为例

1
2
3
4
5
6
​​# 全局更新 Hexo CLI​​
npm install -g hexo-cli@latest

#​​ 更新项目依赖 ​​
npm update
npm install --save hexo@latest

配置 proxy

1
2
3
4
5
6
7
8
9
10
# 查看当前配置
npm config get proxy
npm config get https-proxy

# 设置代理
npm config set proxy http://localhost:7890
npm config set https-proxy http://localhost:7890

set HTTP_PROXY=http://localhost:7890
set HTTPS_PROXY=http://localhost:7890

如果不用代理,可以制定镜像源。默认镜像为 https://registry.npmjs.org/,可以更改为淘宝镜像以加快下载速度。

1
2
3
npm config set registry https://registry.npmmirror.com/
npm config get registry
npm config rm registry # 恢复默认镜像

Nvm 下载和 Node.js 环境配置
https://blog.gtbcamp.cn/article/nodejs/
作者
Great Thunder Brother
发布于
2025年7月28日
更新于
2025年8月14日
许可协议