How to Check Angular Version
- Method 1: Using Angular CLI
- Method 2: Checking package.json
- Method 3: Using npm list Command
- Conclusion
- FAQ

Angular is one of the most popular frameworks for building web applications, and knowing the version you’re working with is crucial for various reasons. Whether you’re troubleshooting an issue, updating your project, or ensuring compatibility with libraries, checking the Angular version can save you a lot of time and headaches.
This tutorial will guide you through multiple methods to check the Angular version effectively. With clear explanations and Python code examples, you’ll be able to determine your Angular version in no time. Let’s dive in!
Method 1: Using Angular CLI
If you have Angular CLI installed, checking your Angular version is as simple as running a command in your terminal. The Angular CLI provides a straightforward way to get the version information. Here’s how you can do it using Python’s subprocess module to execute the command.
import subprocess
def check_angular_version():
result = subprocess.run(['ng', '--version'], capture_output=True, text=True)
return result.stdout
angular_version = check_angular_version()
print(angular_version)
Output:
Angular CLI: 12.0.0
Node: 14.17.0
Package Manager: npm 6.14.13
OS: win32 x64
This code snippet uses the subprocess
module to run the Angular CLI command ng --version
. The capture_output=True
argument allows us to capture the output directly from the command line. The text=True
argument ensures that the output is returned as a string. When you run this function, it will display the Angular CLI version along with the Node version and other related information. This method is particularly useful if you are actively developing and have the Angular CLI installed.
Method 2: Checking package.json
Another effective way to check your Angular version is by examining the package.json
file in your project directory. This file contains all the dependencies and their respective versions, including Angular. You can easily read this file using Python.
import json
def get_angular_version_from_package_json(file_path):
with open(file_path, 'r') as file:
data = json.load(file)
return data['dependencies']['@angular/core']
angular_version = get_angular_version_from_package_json('path/to/your/package.json')
print(angular_version)
Output:
12.0.0
In this example, we open the package.json
file and load its contents using Python’s built-in json
module. We then access the dependencies
dictionary to retrieve the version of @angular/core
. This method is particularly useful for projects that may not have the Angular CLI installed or for those who want to get a quick overview of the Angular version being used in their project. Just make sure to replace 'path/to/your/package.json'
with the actual path to your package.json
file.
Method 3: Using npm list Command
If you prefer using npm, you can also check your Angular version by running the npm list
command. This command provides a detailed list of installed packages, including Angular. You can execute this command through Python as well.
import subprocess
def check_angular_version_npm():
result = subprocess.run(['npm', 'list', '@angular/core'], capture_output=True, text=True)
return result.stdout
angular_version = check_angular_version_npm()
print(angular_version)
Output:
└── @angular/core@12.0.0
In this snippet, we use the subprocess
module again to run the npm list @angular/core
command. This command lists the installed version of the Angular core package. The output will show you the version number along with the package name. This method is particularly useful if you are already familiar with npm and prefer using it over Angular CLI.
Conclusion
Knowing how to check your Angular version is essential for any developer working with this powerful framework. Whether you choose to use Angular CLI, inspect the package.json
file, or run an npm command, each method has its advantages. By following the steps outlined in this tutorial, you can quickly determine your Angular version and ensure your project is up to date. With this knowledge, you’ll be better equipped to manage your Angular applications effectively.
FAQ
- How do I find the Angular version without using the command line?
You can check thepackage.json
file in your project directory. Look for the@angular/core
dependency to find the version number.
-
Can I check the Angular version in a production environment?
Yes, you can check the version in a production environment by accessing thepackage.json
file or using thenpm list
command if you have access to the server. -
What if I don’t have Angular CLI installed?
You can still check the version by looking at thepackage.json
file or using the npm command to list the installed Angular packages. -
Is it necessary to know the Angular version?
Yes, knowing the version is important for compatibility with libraries, troubleshooting issues, and applying updates effectively. -
Can I check the Angular version in a specific component?
No, Angular version is generally checked at the project level, not within individual components.
Rana is a computer science graduate passionate about helping people to build and diagnose scalable web application problems and problems developers face across the full-stack.
LinkedIn