6

I've installed Angular-CLI using this command

npm install -g @angular/cli

but I've realized that it has installed Angular v5.1.3 but I need to use Angular 4.x.

How can I install the last version of Angular-CLI with the last version of Angular 4.x?

6 Answers 6

11

you can use

 npm i @angular/[email protected] -g

if you want package JSON file with the versions lower than 5.

Starting with v1.5 of the Angular CLI, we have added support for Angular v5.0.0 and will generate v5 projects by default. see link

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

1 Comment

Those who are facing errors in windows while running this command can try using node v12, It worked for me.
6

You can use a simple hack: locally install @angular/[email protected] and use it to generate a new project.

To do that, follow these steps:

  1. In a new folder create a simple nodejs project with the command npm init
  2. Locally install angular-cli 1.4 under this project: npm install @angular/[email protected]
  3. Delete the node project files except the newly created node_modules folders: this means that you will need to delete package.json and any other that it has may be created like karma.js etc.
  4. Now you can create a new Angular 4 project with the command ng new <project name>. It will use the local version of angular-cli previously installed.
  5. You may now remove the node_modules folder.

Then, if you cd in your new project you will have a fully Angular 4 project.

Comments

5

I think downgrade your cli is not good idea becuase they are fixing lots of bug. You can specific your angular in package.json file. don't depend on your cli.

Edit

First install latest version from your cli. Then Specify the version you want in the 'dependencies' section of your package.json. For example if you want Angular 4.3.4 then you can edit you package.json file like

"dependencies": {
    "@angular/animations": "^4.3.4",
    "@angular/common": "^4.3.4",
    "@angular/compiler": "^4.3.4",
    "@angular/core": "^4.3.4",
    "@angular/forms": "^4.3.4",
    "@angular/http": "^4.3.4",
    "@angular/platform-browser": "^4.3.4",
    "@angular/platform-browser-dynamic": "^4.3.4",
    "@angular/router": "^4.3.4",
     ...........................
     ...........................
    }

Also change your devDependencies

    "devDependencies": {
      "@angular/compiler-cli": "^4.3.4",
      "@angular/language-service": "^4.3.4",
      .............
    }

and change package-lock.json

{
.........
  "packages": {
    "": {
............
      "dependencies": {
        "@angular/animations": "^4.4.4",
        "@angular/common": "^4.4.4",
        "@angular/compiler": "^4.4.4",
        "@angular/core": "^4.4.4",
          .............
        }

now run npm install

  npm install

After finishing install you should see your version by ng -v command like this

Angular CLI: 1.6.3
Node: 9.3.0
OS: linux x64
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, tsc-wrapped

@angular/cli: 1.6.3
@angular-devkit/build-optimizer: 0.0.38
@angular-devkit/core: 0.0.25
@angular-devkit/schematics: 0.0.48
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.3
@schematics/angular: 0.1.13
@schematics/schematics: 0.0.13
typescript: 2.4.2
webpack: 3.10.0

2 Comments

I tried to use Angular 4 using the following command ng new angular4test --ng4 using Angular-CLI v1.6.4 but I see this in the package.json file "dependencies": {"@angular/core": "^5.1.0"}. Would you please tell me how to specify the version 4 of Angular?
@vcRobe I've edited my answer and see how to specify your angular version
2

You can use

npm install -g @angular/[email protected]

This should install Angular 4.4.6 and will use angular-cli 1.5.5

This was the latest version before 5 came in

1 Comment

It will install 4.4.6
0

This means you installed @angular/cli globally on your computer so that you can use the ng commands from anywhere on a console.

You need to create a new Angular Project using ng new my-project-name which will generate all the basic files you need for an Angular project.

In these files, you will find a package.json file that contains all the library references you need in your project. It should have the angular package by default at version 5+.

To be 4.X.X like you want, you need to find the best @angular/cli version compatible with the Angular version you want (I advise using 1.5.0 or less for @angular/cli).

Comments

0

Using npm install -g @angular/cli you will install the lastest stable version of the @angular/cli. So once you create an angular project using the cli there will be a package.json file, to specify the version of angular to use for the project change the version you would like to use in the package.json file. Then run npm install.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.