Skip to main content

安装 Ionic

Ionic 应用主要通过 Ionic command-line 实用程序创建和开发。Ionic CLI 是首选的安装方法,因为它提供了广泛的开发工具和帮助选项。它也是运行应用并将其连接到其他服务(例如 Appflow)的主要工具。

¥Ionic apps are created and developed primarily through the Ionic command-line utility. The Ionic CLI is the preferred method of installation, as it offers a wide range of dev tools and help options along the way. It is also the main tool through which to run the app and connect it to other services, such as Appflow.

Try our App Wizard

Use our App Wizard to generate an Ionic project visually. Choose a template, custom colors, app icon, and JavaScript Framework to get building quicker.

安装 Ionic CLI

¥Install the Ionic CLI

在继续之前,请确保你的计算机已安装 Node.js。请参阅 这些说明 设置 Ionic 环境。

¥Before proceeding, make sure your computer has Node.js installed. See these instructions to set up an environment for Ionic.

使用 npm 安装 Ionic CLI:

¥Install the Ionic CLI with npm:

npm install -g @ionic/cli

如果以前安装过 Ionic CLI,则由于包名称发生更改,需要将其卸载。

¥If there was a previous installation of the Ionic CLI, it will need to be uninstalled due to a change in package name.

$ npm uninstall -g ionic
$ npm install -g @ionic/cli

注意

-g 选项表示全局安装。全局安装软件包时,可能会出现 EACCES 权限错误。考虑将 npm 设置为在无需提升权限的情况下进行全局操作。请参阅 解决权限错误 了解更多信息。

¥The -g option means install globally. When packages are installed globally, EACCES permission errors can occur. Consider setting up npm to operate globally without elevated permissions. See Resolving Permission Errors for more information.

启动应用

¥Start an App

使用预制应用模板之一创建 Ionic 应用,或使用空白模板重新开始。三种最常见的起动机是 blank 起动机、tabs 起动机和 sidemenu 起动机。开始使用 ionic start 命令:

¥Create an Ionic app using one of the pre-made app templates, or a blank one to start fresh. The three most common starters are the blank starter, tabs starter, and sidemenu starter. Get started with the ionic start command:

ionic start

Three thumbnail previews of Ionic app templates: blank, tabs, and side menu.

要了解有关启动 Ionic 应用的更多信息,请参阅 入门指南

¥To learn more about starting Ionic apps, see the Starting Guide.

运行应用

¥Run the App

大部分 Ionic 应用开发都可以使用 ionic serve 命令在浏览器中进行:

¥The majority of Ionic app development can be spent right in the browser using the ionic serve command:

$ cd myApp
$ ionic serve

还有许多其他方法可以运行应用,建议从此工作流程开始。要在设备和模拟器上开发和测试应用,请参阅 运行应用指南

¥There are a number of other ways to run an app, it's recommended to start with this workflow. To develop and test apps on devices and emulators, see the Running an App Guide.