2

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

npm install -g @angular/cli@8.3.19. 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?

Lost
  • 12,007
  • 32
  • 121
  • 193
  • 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. – meriton May 02 '21 at 00: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. – Roddy of the Frozen Peas May 02 '21 at 00: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` – Lost May 02 '21 at 18:04

1 Answers1

2

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.

Andrew Halil
  • 1,195
  • 15
  • 15
  • 21
  • 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` – Lost May 02 '21 at 16:42
  • 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. – Andrew Halil May 03 '21 at 03:40
  • 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 – Lost May 03 '21 at 20:55
  • What I suggested has worked for me in the past. Another suggestion is to reinstall the NPM in this link https://stackoverflow.com/questions/49748307/how-to-reinstall-broken-npm – Andrew Halil May 04 '21 at 00:26
  • 1
    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. – Lost May 04 '21 at 20:33