How to install Angular-CLI with Angular v4.x
Asked Answered
O

6

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?

Outleap answered 12/1, 2018 at 17:6 Comment(0)
R
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
Rollway answered 12/1, 2018 at 17:27 Comment(2)
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?Outleap
@Outleap I've edited my answer and see how to specify your angular versionRollway
T
10

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

Trella answered 12/1, 2018 at 17:20 Comment(1)
Those who are facing errors in windows while running this command can try using node v12, It worked for me.Phrixus
O
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.

Okinawa answered 28/8, 2018 at 23:38 Comment(0)
R
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
Rollway answered 12/1, 2018 at 17:27 Comment(2)
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?Outleap
@Outleap I've edited my answer and see how to specify your angular versionRollway
M
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

Mayes answered 12/1, 2018 at 17:33 Comment(1)
It will install 4.4.6Mayes
S
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).

Singularity answered 12/1, 2018 at 17:21 Comment(0)
N
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.

Nolte answered 5/8, 2018 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.