How to Use the Angular Version Check Command in Your Project
Run ng version from your Angular project root to display the framework, CLI, and dependency versions.
The Angular CLI provides a built-in command to verify which version of Angular your project is currently using. This is essential when debugging compatibility issues, upgrading dependencies, or verifying CI/CD environments. According to the official Angular documentation in the angular/angular repository, the ng version command remains the standard method for checking your application's Angular version.
Using the ng version Command
The primary method to check your Angular version is the CLI's built-in version command.
Basic Usage
Execute the following command from the root directory of your Angular workspace:
ng version
Alternatively, you can use the shorthand alias:
ng v
Understanding the Output
The command prints a structured table containing:
- Angular CLI version (
@angular/cli) - Angular framework version (
@angular/core) - Node.js version currently active
- Package manager version (npm, yarn, or pnpm)
- Operating system information
- All Angular packages installed in
node_moduleswith their respective versions
Typical output looks like this:
Angular CLI: 16.2.5
Node: 18.17.0
Package Manager: npm 9.6.7
OS: darwin x64
Angular: 16.2.4
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Alternative Methods to Check Angular Version
While ng version is the standard approach, you may need programmatic or automated alternatives.
Reading package.json Programmatically
If you need to access the version number within a Node.js script (for example, in CI checks or build tools), read the @angular/core version directly from its package.json:
import { readFileSync } from 'fs';
import { join } from 'path';
const pkg = JSON.parse(
readFileSync(join(process.cwd(), 'node_modules/@angular/core/package.json'), 'utf-8')
);
console.log(`Angular core version: ${pkg.version}`);
This approach accesses the same version constant defined in packages/core/src/version.ts within the Angular source code.
CI/CD Version Verification
For automated pipelines, you can enforce minimum version requirements using shell commands:
# Example GitHub Actions step that fails if Angular version is older than 16
- name: Verify Angular version
run: |
MIN_VERSION=16
ACTUAL=$(npm list @angular/core --depth=0 | grep '@angular/core@' | cut -d'@' -f3 | cut -d'.' -f1)
if [ "$ACTUAL" -lt "$MIN_VERSION" ]; then
echo "Angular version $ACTUAL is too old. Minimum required is $MIN_VERSION."
exit 1
fi
Where Angular Version Information Is Defined
The version data displayed by ng version originates from specific files within the Angular repository.
The core framework version is defined in packages/core/src/version.ts, which exports a VERSION constant used throughout the framework. This file contains the major, minor, and patch version numbers that correspond to the semantic versioning of Angular releases.
The CLI command implementation references this data while also gathering version information from node_modules to provide the comprehensive output you see when running ng version. The official documentation confirming this behavior is located in adev/src/content/best-practices/update.md, which explicitly states that developers should use the ng version command from within their project directory to check their Angular version.
Summary
- Use
ng version(orng v) from your project root to display all Angular-related versions in a formatted table. - The command reads version data from
packages/core/src/version.tsand your localnode_modulesto show framework, CLI, and dependency versions. - For programmatic access, read
node_modules/@angular/core/package.jsondirectly in Node.js scripts. - For CI/CD pipelines, parse the output of
npm list @angular/coreto enforce minimum version requirements.
Frequently Asked Questions
What is the difference between ng version and ng --version?
Both commands produce identical output. The Angular CLI accepts ng version, ng --version, and ng v as valid aliases for the same version-checking functionality. Use whichever syntax you find more memorable.
Why does ng version show different versions for Angular CLI and Angular Core?
The Angular CLI (@angular/cli) and the Angular framework (@angular/core) follow independent release cycles and semantic versioning. The CLI is a build tool while Core is the runtime framework, so they may have different version numbers even in the same project. Always verify both versions when debugging compatibility issues.
Can I check the Angular version without having the CLI installed?
Yes. If you only have the built application, check the package.json file in your project root or look inside node_modules/@angular/core/package.json for the version field. In browser DevTools, you can also check window.ng or inspect the source maps if available, though the CLI command remains the most reliable method.
How do I check the Angular version in a deployed production application?
For deployed apps, you cannot run ng version on the server unless you have the full source code and CLI installed. Instead, expose the version through your application code by importing the VERSION token from @angular/core and displaying it in your UI or logging it to the console during app initialization.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →