0

I need to install Angular CLI in the version 1.6.8. When I am executing this command:

npm install -g @angular/cli@1.6.8

it is getting installed well. But when I am check the version using ng -v, it displays the latest version, in my case 1.7.4.

For my code compatibility, I need version 1.6.8. And even in my dependencies in package.json, I have specified the cli as version 1.6.8 :

"@angular/cli": "^1.6.8"

Does anybody know the issue? How can I install version 1.6.8?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Chinaedu Onwukwe
  • 437
  • 1
  • 7
  • 20

2 Answers2

2

if you are inside a directory that has node_modules ng -v would report that version, not the global one. For updating your global CLI, move to a directory that doesn't have node_modules installed and then execute

npm uninstall -g @angular-cli
npm cache clean
npm install -g @angular/cli@1.6.8

You can change the version of the angular-cli in the package.json if you want to stick to the particular version remove the ^ symbol but this would be local

"@angular/cli": "1.6.8"

^ it means update the minor and patch version to the latest and keep the major version same.

Vikas
  • 11,859
  • 7
  • 45
  • 69
1

This command will install the CLI globally on your machine.

npm install -g @angular/cli@1.6.8

So, if you have an application that already has CLI version 1.7.4 included in it, you will see that version when you run ng -v. If you would like to downgrade to an earlier version, change the version in the package.json to the exact version you would like to use, and run npm install.

In your package.json you have this:

"@angular/cli": "^1.6.8"

What you need to change it to is this:

"@angular/cli": "1.6.8"

Remove the caret from the version number.

The caret tells npm that is can install versions of a library higher than what is listed, but only if the version is a minor or patch change. So, going from version 1.6.8 to 1.7.4 is OK, but it won't jump to version 6.0.0 when that comes out.

See here for more details.

R. Richards
  • 24,603
  • 10
  • 64
  • 64