How to Angular Install Locally Without the Global Flag: Complete Guide
Install the Angular CLI as a dev dependency using npm install @angular/cli --save-dev and execute commands via npx ng or npm scripts to maintain version isolation between projects.
Performing an angular install locally eliminates version conflicts that plague global installations. When you install @angular/cli as a project dependency rather than using the -g flag, each workspace maintains its own CLI version, ensuring reproducible builds across development teams and CI pipelines.
Why Global Angular CLI Installation Causes Conflicts
The Version Clash Problem
When you run npm install -g @angular/cli, the same binary serves every project on your machine. According to the Angular source documentation in adev/src/content/tools/cli/setup-local.md, this creates conflicts when different repositories require different CLI releases.
Benefits of Local Installation
- Version isolation: Each project pins its own CLI version in
package.json - No elevated privileges: Avoids
sudoor PowerShell execution policy workarounds - CI compatibility: Fresh installs on each build guarantee reproducible environments
How to Perform an Angular Install Locally
Step 1: Install the CLI as a Dev Dependency
Navigate to your project directory and run:
npm install @angular/cli --save-dev
For pnpm or yarn:
pnpm add -D @angular/cli
yarn add -D @angular/cli
This adds @angular/cli to your package.json devDependencies and installs the binary to node_modules/.bin/ng.
Step 2: Create a New Angular Workspace
Use npx to execute the locally installed CLI:
npx ng new my-app
As documented in the Angular repository's skills/dev-skills/angular-new-app/SKILL.md, the npx command resolves ng from node_modules/.bin/ng, guaranteeing the locally-installed version executes regardless of any global installation.
Step 3: Configure npm Scripts for Convenience
Add scripts to your package.json to simplify CLI usage:
{
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test"
},
"devDependencies": {
"@angular/cli": "16.2.0"
}
}
Now execute commands without npx:
npm run ng -- generate component hero
npm start
npm run build
Understanding the Local Installation Architecture
When you perform an angular install locally, the CLI creates several key files:
node_modules/.bin/ng: The executable shim thatnpxresolves to, pointing to the locally installed CLI binarypackage.json: Contains the@angular/clientry underdevDependencies, pinning the exact version for reproducible buildsangular.json: Workspace configuration generated by the local CLI, containing project-specific settings independent of other workspacestsconfig.json: TypeScript configuration scoped to the workspace, created by the local CLI version
According to the Angular source in adev/src/content/introduction/installation.md, this architecture ensures that subsequent CLI calls reuse the local version because node_modules/.bin is on the PATH when using npx or npm scripts.
Verifying Your Local Angular Installation
Confirm you're using the local CLI version:
npx ng version
Or via npm script:
npm run ng -- version
The output displays the version from node_modules/@angular/cli, confirming that your angular install locally is active rather than any global installation.
Summary
- Install locally using
npm install @angular/cli --save-devto avoid version conflicts between projects - Execute via
npx(e.g.,npx ng new my-app) to guarantee the locally installed CLI runs instead of a global binary - Use npm scripts in
package.jsonto simplify commands likenpm startandnpm run build - Verify local usage by running
npx ng versionto confirm the path resolves tonode_modules/@angular/cli - Benefit from isolation – each project maintains independent CLI versions, ensuring reproducible builds across development teams and CI pipelines
Frequently Asked Questions
Can I have both global and local Angular CLI installations?
Yes. When you run npx ng, it prioritizes the locally installed version in node_modules/.bin/ng over any global installation. This allows legacy projects to use older CLI versions while new projects use current releases, preventing the version conflicts that occur when relying solely on global installs.
How do I update the Angular CLI when it's installed locally?
Modify the version in your package.json devDependencies and run npm install. For example, change "@angular/cli": "16.2.0" to "@angular/cli": "17.0.0" and execute npm install. This updates only the current project, leaving other workspaces unaffected, which is the primary advantage of performing an angular install locally.
Will local installation work on CI/CD pipelines?
Yes. Local installation is actually preferred for CI/CD because it eliminates the need for global package installation permissions. The pipeline simply runs npm ci (or npm install) to populate node_modules, then executes npx ng build or npm run build. This guarantees the exact CLI version specified in package.json is used for every build, ensuring reproducible deployments.
What happens if I forget to use npx and just type ng?
If you type ng directly without npx and without an npm script, your shell searches the global PATH. If a global Angular CLI exists, that version executes, potentially causing version mismatches. To prevent this, always use npx ng for one-off commands or define npm scripts in package.json that reference the local binary directly.
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 →