To check the Capacitor version, you can primarily use the Capacitor CLI or inspect your project's configuration files. The most direct method for the CLI version involves a simple command-line input.
Understanding Capacitor Versions
Capacitor is an open-source native runtime that allows you to build web apps that run natively on iOS, Android, Electron, and the web. Managing its version is crucial for ensuring compatibility with plugins, accessing new features, and troubleshooting potential issues within your project. There are two main aspects to a "Capacitor version": the version of the Capacitor Command Line Interface (CLI) tool you're using, and the version of the Capacitor libraries (like @capacitor/core
) installed in your specific project.
Checking the Capacitor CLI Version
The Capacitor CLI provides tools to manage your Capacitor project, including commands for adding platforms, syncing code, and building your app. Knowing its version helps you understand which CLI features are available to you.
Using the Command Line Interface (CLI)
You can quickly determine the version of the Capacitor CLI tool available in your environment by running a command in your terminal. This command executes the cap
utility, which is part of Capacitor's command-line toolset.
-
Output the Capacitor CLI version:
npx cap --version
Alternatively, you can use the shorthand flag:
npx cap -V
Example Output:
@capacitor/cli: 5.0.0
The
npx
prefix is used to execute thecap
command from your localnode_modules
directory, ensuring you're running the version associated with your project or the latest available if not locally installed, without needing to install it globally.
Checking Capacitor Library Versions in Your Project
While the CLI version is important, the versions of the actual Capacitor libraries installed as dependencies in your project are often more critical for development. These are the specific versions of @capacitor/core
, @capacitor/ios
, @capacitor/android
, and any Capacitor plugins that your application relies on.
Inspecting package.json
Every Node.js project, including Capacitor projects, has a package.json
file in its root directory. This file lists all project dependencies and their specified versions.
-
Open
package.json
: Navigate to the root of your Capacitor project and open thepackage.json
file. -
Locate Dependencies: Look for the
"dependencies"
or"devDependencies"
sections. Here, you'll find the declared versions of Capacitor's core libraries and any installed plugins.Example
package.json
snippet:{ "name": "my-capacitor-app", "version": "1.0.0", "dependencies": { "@angular/animations": "^17.0.0", "@capacitor/android": "^5.0.0", "@capacitor/app": "^5.0.0", "@capacitor/core": "^5.0.0", "@capacitor/haptics": "^5.0.0", "@capacitor/keyboard": "^5.0.0", "@capacitor/status-bar": "^5.0.0", "rxjs": "~7.8.0", "zone.js": "~0.14.0" }, "devDependencies": { "@capacitor/cli": "^5.0.0", "@types/node": "^18.18.0", } }
This shows the declared versions. The
^
(caret) symbol indicates that npm or Yarn can install minor and patch updates above the specified version without breaking changes.
Using npm or Yarn for Installed Versions
To see the exact versions of packages currently installed in your node_modules
directory (which might be slightly newer than the declared versions in package.json
due to caret ranges), you can use npm list
or yarn why
.
-
For specific Capacitor packages using npm:
npm list @capacitor/core npm list @capacitor/android npm list @capacitor/ios
Example Output:
[email protected] /path/to/your-project └─┬ @capacitor/[email protected] └── @capacitor/[email protected] deduped
-
For specific Capacitor packages using Yarn:
yarn why @capacitor/core
Example Output:
yarn why v1.22.19 [1/4] Why do you need to know? [2/4] Initializing project for usage with plugins... [3/4] Listing all dependencies... [4/4] Listing dependents... info Reasons this module exists ... info Found "@capacitor/[email protected]"
Why Version Management Is Crucial
- Compatibility: Ensuring all Capacitor components, plugins, and native platforms are compatible with each other.
- Troubleshooting: Knowing the exact versions helps when debugging issues or seeking support, as solutions often depend on the specific version.
- Feature Access: Newer versions introduce new features, performance improvements, and bug fixes.
- Security: Staying updated with the latest versions can provide critical security patches.
Summary of Commands
Here's a quick reference for checking Capacitor versions:
Command | Purpose |
---|---|
npx cap --version |
Output the Capacitor CLI tool's version. |
cat package.json |
View your project's declared Capacitor library versions (e.g., @capacitor/core ). |
npm list @capacitor/core |
Show the exact installed version of @capacitor/core in your project. |
yarn why @capacitor/core |
Show the exact installed version of @capacitor/core in your project (using Yarn). |
By utilizing these methods, you can efficiently track and manage the Capacitor versions relevant to your development environment and projects.