如何在 Ubuntu 20.04 LTS 上安装 ReactJS

在本教程中,我们将向您展示如何在 Ubuntu 20.04 LTS 上安装 ReactJS。 对于那些不知道的人,React 是一个用于创建 Web 前端和 UI 组件的开源 JavaScript 库。 它由 Facebook 和一个大型开发者社区开发和维护。 ReactJS 可用于 Web 应用程序或移动应用程序的开发。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 Ubuntu 20.04 (Focal Fossa) 上逐步安装 ReactJS。 对于 Ubuntu 18.04、16.04 和任何其他基于 Debian 的发行版(如 Linux Mint),您可以按照相同的说明进行操作。

在 Ubuntu 20.04 LTS Focal Fossa 上安装 ReactJS

步骤 1. 首先,通过运行以下命令确保所有系统包都是最新的 apt 终端中的命令。

sudo apt update sudo apt upgrade

步骤 2. 安装 Node.js。

现在我们将 Node.js PPA 添加到您的 Ubuntu 系统中:

curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -

接下来,运行以下命令来安装 Node.js:

sudo apt install nodejs

你也可以在你的 Ubuntu 系统上安装 Yarn 包管理器:

npm install -g yarn

步骤 3. 创建一个新的 React.js 应用程序。

您可以使用以下命令之一创建 React.js 应用程序:

yarn create react-app myreactapp

成功创建应用程序后,您将在屏幕上看到一个很长的结果:

Success! Created reactproject at /opt/reactproject Inside that directory, you can run several commands:    npm start     Starts the development server.    npm run build     Bundles the app into static files for production.    npm test     Starts the test runner.    npm run eject     Removes this tool and copies build dependencies, configuration files     and scripts into the app directory. If you do this, you can’t go back!  We suggest that you begin by typing:    cd reactproject   npm start

一旦你创建了你的 React 应用程序。 这将在当前目录中使用项目名称创建一个文件夹。 切换到该项目并运行 yarn start 启动应用程序:

cd myreactapp yarn start

输出:

Compiled successfully!  You can now view myreactapp in the browser.    https://localhost:3000  Note that the development build is not optimized. To create a production build, use yarn build.

恭喜! 你已经成功安装了 ReactJS。 感谢您使用本教程在您的 Ubuntu 20.04 LTS Focal Fossa 系统上安装 ReactJS。 如需更多帮助或有用信息,我们建议您查看 ReactJS 官方网站.