article illustration Installing Capacitor CLI: Step-by-Step Guide
Development, Mobile, Updates
Last update: April 04, 2025

Installing Capacitor CLI: Step-by-Step Guide

Learn to install and configure Capacitor CLI for transforming web apps into native mobile apps efficiently.

Capacitor CLI helps you transform web apps into native iOS and Android apps with one codebase. Here’s how to set it up quickly:

  • Prerequisites: Install Node.js (v16+), npm, and a web framework (React, Vue, Angular, etc.).
  • Install Capacitor CLI: Run npm install @capacitor/cli @capacitor/core and initialize your project with npx cap init.
  • Prepare Platforms: Add support for iOS (npx cap add ios) and Android (npx cap add android) platforms.
  • Build and Sync: Use npm run build and npx cap sync to transfer web assets to native projects.
  • Optional Live Updates: Use tools like Capgo to push updates instantly without app store delays.

Capacitor CLI simplifies app development and maintenance. Follow the guide for smooth setup and troubleshooting.

Build a Mobile App Fast! React + Capacitor + Tailwind + DaisyUI

Capacitor

Before You Start

Get your environment ready by following these steps:

Set Up Node.js and npm

Node.js

You’ll need Node.js version 16 or higher. The latest LTS version is recommended. To check your setup, run:

Terminal window
node --version
npm --version

If you need to update, download Node.js (which includes npm) from the official website.

After confirming Node.js is ready, ensure your web project meets the necessary Capacitor requirements.

Check Your Web Project

Your web project should have the following:

  • A valid package.json: Make sure it’s properly configured.
  • A build directory: This is where your web assets live (commonly dist or www).
  • An entry point: Your build directory must include an index.html file.

Here’s a quick look at key package.json fields:

Required FieldExample ValuePurpose
name”my-app”Identifies the project
version”1.0.0”Specifies app version
build directory”dist” or “www”Points to web assets

Once your Node.js and web project are ready, move on to installing platform-specific tools.

Install Required Software

For Android Development:

  • Download and install the latest version of Android Studio.
  • Set up the Android SDK with at least API level 22.
  • Configure the ANDROID_HOME environment variable.

For iOS Development (Mac only):

  • Install Xcode 14 or a newer version.

  • Install Command Line Tools.

  • Use Homebrew to install CocoaPods:

    Terminal window
    brew install cocoapods
  • Accept the Xcode license:

    Terminal window
    sudo xcodebuild -license accept

When integrating Capgo later, make sure you have a stable internet connection and valid SSL certificates.

With these steps done, you’re set for a smooth Capacitor development process. Next, you’ll install the Capacitor CLI.

Install Capacitor CLI

With your environment ready, it’s time to install and configure Capacitor CLI.

Add Capacitor Packages

Start by installing the Capacitor CLI and Core packages using npm:

Terminal window
npm install @capacitor/cli @capacitor/core

Once installed, confirm the setup by checking the Capacitor version:

Terminal window
npx cap --version

Set Up Your Project

Initialize Capacitor in your project with the following command:

Terminal window
npx cap init

During initialization, you’ll be prompted to provide these details:

SettingDescriptionExample
App NameThe name displayed in app stores”My Awesome App”
App IDA unique identifier for your app”com.mycompany.myapp”
Web DirectoryPath to your web assets”dist” or “www”

Next, update your configuration file (capacitor.config.ts or capacitor.config.json) with the relevant settings:

import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.mycompany.myapp',
appName: 'My Awesome App',
webDir: 'dist',
bundledWebRuntime: false
};
export default config;

Set Up iOS and Android

Add support for iOS and Android platforms with these commands:

Terminal window
npx cap add ios
npx cap add android

This will generate native projects:

  • iOS: Creates an ios folder containing the Xcode project.
  • Android: Creates an android folder for the Android Studio project.

After making any changes to your web assets, run the following commands to build and sync:

Terminal window
npm run build
npx cap sync

This process compiles your web assets and transfers them to the native projects, including any installed Capacitor plugins.

To open the native projects for further customization:

Terminal window
npx cap open ios # Opens Xcode
npx cap open android # Opens Android Studio

Now you’re ready to test your setup and resolve any issues that may arise.

Fix Common Problems

When setting up Capacitor CLI, you might run into a few common hiccups. Here’s how to tackle them:

Android Gradle Issues

If you’re facing Gradle-related problems, try these steps:

  1. Navigate to the Android directory and clear the build cache:

    Terminal window
    cd android
    ./gradlew cleanBuildCache
  2. Update the Gradle version in android/build.gradle:

    buildscript {
    ext {
    gradleVersion = '8.1.0'
    }
    }
  3. Add the following lines to android/gradle.properties for better performance:

    org.gradle.jvmargs=-Xmx4608m
    org.gradle.parallel=true

If problems persist, revisit your setup or consult additional troubleshooting resources.

App Shows Blank Screen

A blank screen usually points to a configuration issue. Here’s how to address it:

  • Check the Web Directory Path: Ensure the webDir matches your build output.

    const config: CapacitorConfig = {
    webDir: 'dist', // Adjust if necessary
    };
  • Verify Server Configuration: Confirm the server settings are correct.

    server: {
    url: 'http://localhost:3000',
    cleartext: true
    }
  • Update Content Security Policy: Add this meta tag to your HTML for proper resource loading.

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval' data: *">

Plugin Not Working

If a plugin isn’t behaving as expected, follow these steps:

  1. Perform a clean installation of dependencies:

    Terminal window
    rm -rf node_modules
    npm cache clean --force
    npm install
  2. Check the plugin settings in capacitor.config.ts to ensure they’re configured correctly:

    plugins: {
    PluginName: {
    option: 'value'
    }
    }

For those using Capgo’s native plugin, it automatically synchronizes plugins and maintains compatibility during updates.

After applying these fixes, rebuild your project to verify the changes:

Terminal window
npm run build && npx cap copy && npx cap sync

Once everything is running smoothly, you can move forward with exploring live update options with Capgo.

Live Updates with Capgo

Capgo

Simplify app updates using Capgo. It lets you push updates directly to users, skipping the need for app store reviews.

Getting started is simple. First, install the necessary packages:

Terminal window
npm install @capgo/cli @capgo/capacitor-updater
npx cap sync

Then, initialize Capgo in your project:

Terminal window
npx @capgo/cli init

Pricing Plans

Capgo offers several pricing tiers to suit different needs:

PlanMonthly Active UsersBandwidthStoragePrice (Annual)
SOLO1,00050 GB2 GB$12/month
MAKER10,000500 GB5 GB$33/month
TEAM100,0002,000 GB10 GB$83/month

For enterprise users, the PAYG plan starts at $249/month and includes perks like API access, custom domains, and dedicated support.

Configuration for Live Updates

To enable live updates, add the following to your capacitor.config.ts file:

{
plugins: {
CapacitorUpdater: {
autoUpdate: true,
updateUrl: 'https://api.capgo.app/updates'
}
}
}

Key Features

Capgo provides several standout features:

  • Secure updates with end-to-end encryption
  • Automated deployments through integrated CI/CD
  • Targeted updates via user assignment
  • Instant rollback with version control
  • Real-time analytics to track updates

Deployment Commands

Test updates in development before deploying them live. Use the following commands:

  • Deploy to staging:

    Terminal window
    npx @capgo/cli deploy --channel staging
  • Deploy to production:

    Terminal window
    npx @capgo/cli deploy --channel production

Capgo ensures compliance with Apple and Android guidelines, so your live updates won’t risk app store violations. It’s an efficient way to manage Capacitor apps after installation.

Conclusion

Setting up Capacitor CLI is simple when you have the right prerequisites in place. This setup ensures smoother app updates and efficient development workflows.

Modern tools make app maintenance easier than ever. For example, Capgo now provides live updates, replacing older methods. Its integration with the CLI installation makes it a great option for developers working with Capacitor apps.

The Capacitor ecosystem is constantly improving with new tools and features. Installing the CLI is just the starting point for building mobile apps, and you’ll benefit from detailed documentation and an active developer community.

Be sure to keep the Capacitor CLI and its packages up to date to avoid compatibility issues.

Authored By

Instant Updates for CapacitorJS Apps

Push updates, fixes, and features instantly to your CapacitorJS apps without app store delays. Experience seamless integration, end-to-end encryption, and real-time updates with Capgo.

Get Started Now

Latest from news

Capgo gives you the best insights you need to create a truly professional mobile app.

blog illustration 5 Common OTA Update Mistakes to Avoid
Development, Security, Updates
April 13, 2025

5 Common OTA Update Mistakes to Avoid

Read more
blog illustration 5 Security Best Practices for Mobile App Live Updates
Development, Mobile, Updates
January 14, 2025

5 Security Best Practices for Mobile App Live Updates

Read more