GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.runoob.com — NVM 管理多版本 Node.js | 菜鸟教程
Node.js 教程
Node.js 教程
Node.js 概念
Node.js 安装配置
Node.js VS Code
Node.js NVM
Node.js 创建第一个应用
Node.js 工作机制
NPM 使用介绍
PNPM 使用介绍
Node.js REPL
Node.js 异步编程
Node.js 回调函数
Node.js Promise
Node.js async/await
Node.js 事件循环
Node.js EventEmitter
Node.js Buffer
Node.js Stream
Node.js 模块系统
Node.js 模块导入
Node.js 函数
Node.js 路由
Node.js 全局对象
Node.js 常用工具
Node.js 文件系统
Node.js 内置模块
Node.js 测验
Node.js 应用Node.js 构建简单应用 Node.js GET/POST请求 Node.js util 模块 Node.js Web 模块 Node.js Express 框架 Node.js RESTful API Node.js 多进程 Node.js JXcore 打包 Node.js MySQL Node.js MongoDB npx 入门教程NVM 管理多版本 Node.jsnvm(Node Version Manager)是一个非常有用的工具,可以让您在同一台机器上安装和管理多个 Node.js 版本。
为什么需要 nvm?
安装 nvm在 macOS/Linux 上安装 nvm: # 使用 curl 安装 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash # 或使用 wget 安装 wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash # 重新加载 shell 配置 source ~/.bashrc # 或 source ~/.zshrc 在 Windows 上安装 nvm-windows:
nvm 常用命令: # 查看 nvm 版本 nvm --version # 列出所有可安装的 Node.js 版本 nvm list-remote # Windows 上使用 nvm list available # 安装最新的 LTS 版本 nvm install --lts # 安装特定版本 nvm install 18.17.0 nvm install 16.20.1 # 列出已安装的版本 nvm list # 或 nvm ls # 切换到特定版本 nvm use 18.17.0 # 设置默认版本 nvm alias default 18.17.0 # 查看当前使用的版本 nvm current # 卸载特定版本 nvm uninstall 16.20.1 实际使用示例: # 场景:为不同项目使用不同 Node.js 版本 # 项目 A 使用 Node.js 18 cd project-a nvm use 18.17.0 node --version # v18.17.0 # 项目 B 使用 Node.js 16 cd ../project-b nvm use 16.20.1 node --version # v16.20.1 # 为项目指定 Node.js 版本 echo "18.17.0" > .nvmrc nvm use # 自动使用 .nvmrc 中指定的版本 验证安装是否成功创建第一个 Node.js 程序: 创建一个名为 实例
// hello.js console.log('Hello, Node.js!'); console.log('Node.js 版本:', process.version); console.log('当前工作目录:', process.cwd()); console.log('操作系统:', process.platform); 预期输出: Hello, Node.js! Node.js 版本: v18.17.0 当前工作目录: /Users/username/projects 操作系统: darwin 检查全局安装路径: # 查看 npm 全局包安装路径 npm config get prefix # 查看 npm 配置 npm config list # 查看 Node.js 安装路径 which node # Windows 上使用 where node
AI 思考中...
点我分享笔记取消
分类导航
Advertisement
|
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |