React - 安装配置 配置详解

综合新闻

React - 安装配置 配置详解

2026-05-03 18:01



React安装配置:从Node.js环境到项目创建,手把手带你完成开发环境搭建

一、前言

干过前端的人都知道,新机器上配React环境是最烦的——Node版本不对、npm源太慢、create-react-app卡在半空,各种坑轮着踩一遍。这次把10年踩坑经验整理出来,照着做10分钟跑起来。

如果显示command not found,说明没装。继续往下看。

步骤2:通过nvm管理Node版本(推荐)

搞前端的都知道,用nvm管理Node版本比直接装强太多了,切换版本不打架。CentOS/RHEL和Ubuntu通用安装方式:

# Ubuntu/Debian
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
$ source ~/.bashrc

# CentOS/RHEL(需要先装git和curl)
$ yum install -y git curl
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
$ source ~/.bashrc

安装完成后验证nvm是否正常工作:

$ command -v nvm
nvm
$ nvm --version
0.39.3

步骤3:安装Node LTS版本

React官方推荐LTS版本,稳定性好。直接用nvm安装:

$ nvm install --lts
Installing node v18.17.0 (with npm 9.6.7)...
$ nvm use --lts
Now using node v18.17.0 (npm 9.6.7)
$ node --version
v18.17.0