Ubuntu 前端开发环境搭建与 Vue 实战
前言
本文讲述在 Ubuntu 上安装 nvm、pnpm 和 Vue 相关开发环境的完整配置。
1. 系统更新和基础依赖
# 更新系统包列表
sudo apt update
sudo apt upgrade -y
# 安装常用工具
sudo apt install -y curl wget git build-essential
2. 安装 nvm (Node Version Manager)
方法一:使用官方脚本安装(推荐)
# 下载并运行安装脚本
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# 或使用 wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
方法二:手动安装
# 从 GitHub 克隆 nvm 仓库
git clone https://github.com/nvm-sh/nvm.git ~/.nvm
cd ~/.nvm
git checkout v0.39.0
# 将以下内容添加到 ~/.bashrc
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' >> ~/.bashrc
激活 nvm
# 重新加载 bash 配置
source ~/.bashrc
# 验证安装
nvm --version
# 查看可安装的 Node.js 版本
nvm ls-remote
# 安装最新的 LTS 版本(推荐)
nvm install --lts
# 查看已安装版本
nvm ls
3. 使用 nvm 安装和管理 Node.js
nvm 常用命令
# 查看可安装的 Node.js 版本
nvm ls-remote
# 安装最新的 LTS 版本(推荐)
nvm install --lts
nvm install 18
nvm install 20
nvm
nvm use 18
nvm default 18
node --version
npm --version
nvm uninstall 18
nvm uninstall 20


