Installing and Configuring Ionic CLI
1. Installing Ionic CLI
The Ionic Command Line Interface (CLI) is the primary tool for creating, building, and managing Ionic applications. It provides a set of commands to scaffold projects, run development servers, build for production, and more.
| Installation Method | Description | Command | Notes |
|---|---|---|---|
| npm | Install globally using npm (Node Package Manager) | npm install -g @ionic/cli |
Requires Node.js (v16 or higher) to be installed |
| yarn | Install globally using yarn | yarn global add @ionic/cli |
Same requirement as npm |
| Homebrew (macOS) | Install using Homebrew on macOS | brew install ionic |
May not always be the latest version |
| Direct Download | Download prebuilt binaries from the Ionic website | https://ionicframework.com/docs/cli |
Manual installation and setup required |
Note: After installing the Ionic CLI, you can run
ionic --help to see all available commands.
Warning: Ensure that Node.js (v16 or higher) is installed before installing the Ionic CLI.
2. Updating Ionic CLI
| Method | Description | Notes |
|---|---|---|
| npm update -g @ionic/cli | Updates the Ionic CLI globally using npm | Ensure you have the latest stable version installed |
| yarn global add @ionic/cli | Updates the Ionic CLI globally using yarn | Alternative to npm for managing global packages |
| ionic update | Checks for and applies updates to the Ionic CLI | May prompt for confirmation before updating |
Note: Always verify the installed version after updating to ensure compatibility with your projects.
3. Checking Ionic Version
| Command | Description | Output |
|---|---|---|
| ionic --version | Displays the installed version of the Ionic CLI | 7.2.0 |
| ionic info | Shows detailed information about the Ionic CLI and environment | Includes CLI version, Node.js version, OS info, etc. |
Example: Ionic Info Output
$ ionic info
Ionic CLI : 7.2.0
Ionic Framework : @ionic/angular 7.6.0
@angular : 16.2.0
Node : v18.17.0
OS : macOS 13.5
4. Viewing Ionic Info
| Command | Description | Notes |
|---|---|---|
| ionic info | Displays detailed information about the Ionic CLI, environment, and project configuration. | Useful for debugging and verifying setup |
Example: Running ionic info
$ ionic info
Ionic CLI: 7.2.0
Ionic SDK: 7.2.0
@ionic/angular: 7.2.0
Node: v18.17.0
OS: macOS 13.5
Note: The
ionic info command is essential for troubleshooting and ensuring your Ionic environment is correctly configured.5. Creating New Project
| Option | Values | Description |
|---|---|---|
| ionic start <name> | myApp |
Name of the new project |
| --type | angular, react, vue |
Framework to use for the project |
| --template | blank, tabs, sidemenu |
Project template to use |
| --cordova | true, false |
Include Cordova integration (deprecated) |
Note: The
--cordova flag is deprecated in favor of Capacitor.Project Creation Workflow
- Run
ionic start <projectName> - Select project type (Angular, React, Vue)
- Choose a starter template
- Optionally include Cordova support (not recommended)
6. Choosing Framework
When setting up an Ionic project, you must choose a framework to use. The choice impacts the development experience, component library, and overall project structure.
| Framework | Description | Use Case | Notes |
|---|---|---|---|
| Angular | Full-featured framework with strong tooling and ecosystem integration. | Large-scale enterprise apps or teams already using Angular. | Uses ionic start with --type=angular. |
| React | Component-based library with a smaller footprint and faster rendering. | Teams familiar with React or building lightweight apps. | Uses ionic start with --type=react. |
| Vue | Progressive framework with a gentle learning curve and flexible architecture. | Developers seeking simplicity or migrating from Vue.js projects. | Uses ionic start with --type=vue. |
| Svelte | Compile-time framework that produces highly optimized JavaScript. | Performance-critical apps or developers preferring compile-time optimizations. | Uses ionic start with --type=svelte. |
Comparison: Angular vs React vs Vue vs Svelte
- Angular: Best for large, complex applications with strict architecture requirements. Requires TypeScript and has a steeper learning curve.
- React: Ideal for building reusable UI components. Offers flexibility in project structure and tooling choices.
- Vue: Great for developers looking for a balance between simplicity and power. Easy to integrate into existing projects.
- Svelte: Excellent for performance-sensitive apps due to its compile-time optimizations. Minimal runtime overhead.
7. Selecting App Template
When creating a new Ionic project, you can choose from several pre-built app templates to accelerate your development process.
| Template | Description | Features | Command |
|---|---|---|---|
| blank | A minimal starter template with no additional components or features. | Basic Ionic structure, minimal dependencies | ionic start myApp blank |
| tabs | A tab-based navigation structure with three pre-defined tabs. | Tab navigation, multiple pages, basic styling | ionic start myApp tabs |
| sidemenu | A side menu navigation pattern, suitable for apps with many sections. | Side menu, navigation, multiple views | ionic start myApp sidemenu |
| list | Template with a list view, useful for data-heavy applications. | List view, data display, basic interactions | ionic start myApp list |
| conference | Template designed for conference or event apps with schedules, speakers, and maps. | Schedule view, speaker profiles, map integration | ionic start myApp conference |
Note: The
ionic start command will prompt you to choose a template if none is specified.
8. Generating Components
| Command | Description | Options |
|---|---|---|
| ionic generate | Generates new components, pages, and services | --dry-run, --verbose |
Note: The CLI will prompt for component details if not provided via flags.
9. Serving Development Server
| Command | Description | Options |
|---|---|---|
| ionic serve | Starts the development server and opens the app in a browser | --browser to specify browser--port to set port--host to bind to host |
| ionic serve --lab | Starts the development server with Ionic Lab UI | --lab enables lab mode--port to set port |
Note: The development server automatically watches for file changes and reloads the app in the browser.
10. Building Application
| Option | Values | Description |
|---|---|---|
| --prod | true |
Builds the app in production mode with optimizations |
| --release | true |
Enables release mode optimizations |
| --platform | ios, android |
Builds for a specific platform |
| --mode | prod, dev |
Sets the build mode (default is dev) |
Note: The
ionic build command uses the underlying framework's build system (e.g., Angular CLI or React scripts) to compile and bundle your application.11. Configuring CLI Settings
| Setting | Description | Default Value | Example |
|---|---|---|---|
| cli.telemetry | Controls whether Ionic CLI collects anonymous usage data | true |
ionic config set cli.telemetry false |
| cli.color | Enables or disables color output in the terminal | true |
ionic config set cli.color false |
| cli.interactive | Enables or disables interactive prompts in the CLI | true |
ionic config set cli.interactive false |
| cli.defaultProject | Sets the default project to use when running commands without specifying a project | null |
ionic config set cli.defaultProject my-app |
Note: Changes to CLI settings are applied globally and affect all Ionic projects on your system.