How to Create a New Angular Project with a Specific Version Using the CLI
Use npx @angular/cli@<version> new <project-name> to scaffold a project with a specific Angular version without affecting your global installation.
The Angular CLI is the official toolchain for creating and managing Angular applications. While the standard ng new command generates projects using your globally installed CLI version, the angular/angular repository provides documentation showing how to target specific Angular releases by controlling the CLI version itself.
How the Angular CLI Handles Versioning
The ng new command, documented in adev/src/content/reference/cli.md, creates a new Angular workspace and an initial application project【/tmp/instagit_1wfe4hah/adev/src/content/reference/cli.md#L16-L17】. The setup guide in adev/src/content/tools/cli/setup-local.md demonstrates the canonical usage of this command for generating new projects【/tmp/instagit_1wfe4hah/adev/src/content/tools/cli/setup-local.md#L120-L126】.
The CLI version is tied directly to the @angular/cli npm package. When you execute ng new, the schematic reads the version of @angular/cli being used and generates a package.json containing matching versions of Angular framework packages (@angular/core, @angular/common, etc.). Therefore, to create a project with a specific Angular version, you must run the corresponding CLI version.
Method 1: Using npx for One-Off Project Generation
The most reliable way to create a new Angular project with a specific version without altering your global installation is using npx. This executes the CLI package at the exact version you specify.
# Create a project using Angular CLI v14
npx @angular/cli@14 new my-app --strict
This command fetches CLI version 14 from the npm registry and runs the new schematic. The generated package.json will contain Angular framework packages locked to the ^14.x.x range, ensuring compatibility with that specific release.
Method 2: Installing a Specific CLI Version Globally
If you frequently work with a specific Angular version, install that CLI version globally. All subsequent ng new commands will use this version until you upgrade.
# Install CLI version 15 globally
npm i -g @angular/cli@15
# Verify the installed version
ng version # Output shows Angular CLI: 15.x.x
# Scaffold a new project
ng new my-app --routing --style=scss
After generation, navigate into the project directory and run ng version again to confirm that both the CLI and the Angular framework packages match your target version.
Pinning Versions in CI/CD Pipelines
In automated environments, explicitly install the desired CLI version to ensure reproducible builds. The following GitHub Actions workflow demonstrates pinning Angular CLI version 16:
# .github/workflows/create-angular.yml
jobs:
create:
runs-on: ubuntu-latest
steps:
- name: Install specific CLI version
run: npm i -g @angular/cli@16
- name: Scaffold project
run: ng new my-app --skip-install
- name: Install exact Angular packages
run: |
cd my-app
npm ci
This approach ensures that the schematic generating the package.json uses the exact CLI version specified, preventing unexpected upgrades in automated project creation.
Verifying the Generated Angular Version
After creating your project, always verify the installed versions match your requirements:
cd my-app
ng version
The output displays both the CLI version and the Angular framework packages (@angular/core, @angular/common, @angular/compiler, etc.). Confirm these align with the specific version you targeted during project creation.
Summary
- Use
npx @angular/cli@<version>to create a project with a specific Angular version without changing your global CLI installation. - Install
@angular/cli@<version>globally if you regularly scaffold projects using a specific Angular release. - The CLI version determines the Angular framework package versions written to the generated
package.json, as documented inadev/src/content/reference/cli.mdandadev/src/content/tools/cli/setup-local.md. - Always run
ng versionafter project creation to verify the installed Angular packages match your target version.
Frequently Asked Questions
Can I create an Angular project with a specific version without installing the CLI globally?
Yes. Use npx @angular/cli@<version> new <project-name> to run a specific CLI version temporarily without installing it globally. This generates a project using the Angular packages that correspond to that CLI version.
How do I check which Angular version was generated in my new project?
Navigate to your project directory and run ng version. This command displays the Angular CLI version along with the versions of all installed Angular framework packages (@angular/core, @angular/common, etc.) listed in your package.json.
Will using npx @angular/cli@14 install Angular 14 packages in my project?
Yes. When you run npx @angular/cli@14, the CLI version 14 executes the new schematic, which generates a package.json containing Angular framework packages locked to version 14 (e.g., @angular/core@^14.x.x).
How do I downgrade an existing Angular project to a specific version?
To downgrade an existing project, manually update the versions of all @angular/* packages in your package.json to your target version, then delete node_modules and package-lock.json before running npm install. Alternatively, use ng update if moving between supported versions, though this typically upgrades rather than downgrades.
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 →