2

I want to install a specific version of angular(In particular 8.3.19). So, I run the command

npm install -g @angular/[email protected]. Now, it is installed on my machine but when I do bg --version, I do see follwing:

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.803.29
@angular-devkit/build-angular   0.803.29
@angular-devkit/core            8.3.29
@angular-devkit/schematics      11.2.11
@angular/cdk                    8.2.3
@angular/cli                    11.2.11
@angular/material               8.2.3
@schematics/angular             11.2.11
@schematics/update              0.1102.11
rxjs                            6.4.0
typescript                      3.5.3
webpack                         4.42.1

which clearly states that angular cli version is 11.2.11, which not what I asked npm to install. I am not sure what I am doing wrong here. I am pretty new to npm and angular. Any suggestions?

3
  • 3
    Erm ... what do you need a global install of an old cli version for? Since the global cli version is mainly used for scaffolding new angular projects, the latest version is usually desired. Commented May 2, 2021 at 0:20
  • 2
    To echo meriton -- it's likely you want to create a project that's Angular 8.3.19 -- in which case that's the local version of Angular, not the global. The local version will be defined in the project's package.json and package-lock.json. The global version is mostly irrelevant. Commented May 2, 2021 at 0:36
  • @meriton and @Roddy I did npm install and it does have angular/cli is defined in dv dependencies but still when I do ng commands after npm install, and it throws ` /usr/local/bin/ng: No such file or directory` Commented May 2, 2021 at 18:04

1 Answer 1

3

If you have unintentionally installed the latest Angular globally and want to go back to a previous version of Angular CLI then try using the commands:

npm uninstall -g angular-cli
npm install -g @angular/cli@[whatever your version is]

(refer to https://www.npmjs.com/package/@angular/cli)

Then re-install dependencies from your package.json within your local project with:

npm install

There is really no need to downgrade the global version as you can install whatever previous versions of Angular in your local projects. In situations where you are installing an Angular project that has a higher version of the CLI than your global version, then in this case you would upgrade the global version, preferably to the latest possible as the packages in the latest Node.js library are backward compatible to previous versions, allowing you to create projects in the previous versions.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you so much for such a clear and detailed answer. I think my problem is two-fold. I agree that when I do have package.json(which I do), All I need to to is either yarn install OR npm install and that should take care of installing all the dependencies including whatever version of agular-cli that it is using. However though, when I do ng serve after npm install, it shows that bash: /usr/local/bin/ng: No such file or directory
Try running ng --version and verify the version of Angular CLI you have. Check also your package.json "devDependencies" section has the "@angular/cli" with the matching CLI version. The node_modules folder should also have a subfolder \@angular\cli after the npm install. Also check your environment path includes the \npm folder. Also try closing your dev environment and re-open, re-build, re-run the app. if that fails, reboot and try again.
Actually i tried everything that you suggested above. Also, I wiped out global node_modules folder and local node_modules folder. I also made sure that I am using the same version of node and npm which is (node 15.1.0 && NPM 7.0.8) still when I do npm install it is missing a good amount of modules including angular-cli. Not sure what else to do
What I suggested has worked for me in the past. Another suggestion is to reinstall the NPM in this link stackoverflow.com/questions/49748307/…
Thank you so much for your comments. They were very very helpful. One thing I realized is that in the last the problems that I was facing were related to a mismatching npm version.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.