linux 下如何安装react
安装 Node.js
React 需要 Node.js 环境。可以通过以下命令安装最新版本的 Node.js:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
验证安装是否成功:
node -v
npm -v
创建 React 应用
使用 create-react-app 工具快速生成 React 项目:
npx create-react-app my-app
进入项目目录:
cd my-app
启动开发服务器
运行以下命令启动开发服务器:
npm start
默认情况下,应用会在浏览器中打开 http://localhost:3000。
安装必要依赖
如果需要额外依赖(如 React Router),可以通过 npm 安装:
npm install react-router-dom
构建生产版本
准备生产环境构建:

npm run build
构建后的文件会生成在 build 目录中。






