angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

How to install angular-cli "locally"

Open jdang67 opened this issue 9 years ago • 20 comments

Hi,

What does this command do? npm install @angular/cli@latest ( without -g)

Is it possible to install multiple angular-cli locally for each project on the same machine? Currently we have 2 projects that using angular-cli.1.0.0.beta.24 and we are working on new project using latest version of angular-cli.

We don't want to spend time work update other 2 projects to work with [email protected]. We just want able to work on both new and old angular-cli.

thanks Jdang

jdang67 avatar Apr 13 '17 19:04 jdang67

The global CLI will always use the CLI installed in your project, whichever version. So if you install globally with a new version but the project has a beta dependency (e.g.) then it will use the beta version of the CLI to perform actions on the project.

hansl avatar Apr 13 '17 19:04 hansl

That is not what we see.
We installed version 1.0.0 globally. We also install 1.0.0-beta.24 for one of the project locally. Inside that project, we run: ng -v it shows angular-cli version 1.0.0. We expect to show 1.0.0-beta.24

jdang67 avatar Apr 13 '17 20:04 jdang67

To run multiple different versions, which are local defined, in parallell is must have for modular development.

Lets consider the following scenario: Team One has not touched code "A"-repo for long time, which was started with 0.8 angular-cli. They continue to work on new code "B" repo with new cli-version 1.0.
Later they need a urgend hotfix on repo "A" like a bugfix.

How can they make sure, angular-cli is generating exact same code for prod in "A" repo, without downgrading to 0.8 cli ?

raDiesle avatar Apr 24 '17 16:04 raDiesle

are there any solutions for this kind of problem and why was the ticket closed?

squadwuschel avatar May 19 '17 11:05 squadwuschel

Yes, we have a solution for this problem.

  1. Install angular-cli version globally that supports the old-application then making sure the old application works.

  2. Install newer angular-cli version globally . Create a new app using newest angular-cli version and making sure it works.

  3. Verify the step 1 still work.

jdang67 avatar May 19 '17 15:05 jdang67

Wow, what an elegant workflow, if you work on two projects in paralell ! irony Just takes you around 5 minutes to reinstall every time.

raDiesle avatar May 19 '17 20:05 raDiesle

David, Our workflow allow to run more than one angular projects with different angular-cli at the same time with out reinstall.

Jdang

jdang67 avatar May 21 '17 19:05 jdang67

I see, But all the versions have to be compatible to each other.

raDiesle avatar May 21 '17 19:05 raDiesle

Well if all the versions have to be able to be compatible to each other then we should upgrade using a single latest version to make our life easier. In our case, we are be able to run angular-cli-beta-24 and current latest version at the same time.

jdang67 avatar May 22 '17 00:05 jdang67

Even I face the same problem. one of my old projects is using angular-cli 1.0.0-beta.14 and I want to work on a new project which is on angular/cli (latest version). can anyone help me on how to switch version without reinstalling?

akashraom avatar Jun 01 '17 13:06 akashraom

From https://stackoverflow.com/questions/42295591/angular-cli-lower-version-locally

In package.json make a script for ng "scripts": { "ng": "ng" }

Calling "npm run-script ng build" will use the local version of the cli. It will work even if you haven't installed the cli globally.

darrhal avatar Aug 04 '17 15:08 darrhal

Thanks darrhal. This also works for "npm run-script ng serve --open"

jswagger avatar Nov 06 '17 18:11 jswagger

its Working fine, all version supported in latest one, but it will show some deprecated message, thats no problem

raghulrajnkl avatar Jan 04 '18 04:01 raghulrajnkl

darrhal, thank you very much!!! It hepled me

chebotarevmichael avatar Jan 27 '18 16:01 chebotarevmichael

One more idea, it might me useful for someone... It's possible to install certain version in parent folder. After that, ng new command will use that version for creating a new project.

mnicic avatar Jun 12 '18 08:06 mnicic

I like the idea of not installing/using global libraries (except of course node and npm). Admittedly, you could be running a vagrant box (or container) for each dev project, then it doesn't matter much. But, for those of us who like developing on bare metal, it is much cleaner to keep local npm "environments" isolated, and mimics what python has been doing with virtualenvs for years.

Making a minor correction to @jswagger 's comment. At least with npm 2.0.0+, You pass arguments to the script by including them after a naked --. For example: npm run ng -- serve --open Or npm run ng -- generate component my-component --module=app

fizxmike avatar Aug 14 '18 21:08 fizxmike

From https://stackoverflow.com/questions/42295591/angular-cli-lower-version-locally

In package.json make a script for ng "scripts": { "ng": "ng" }

Calling "npm run-script ng build" will use the local version of the cli. It will work even if you haven't installed the cli globally.

"run" is an alias for "run-script" in npm, so can also do npm run ng build or npm run ng start

When I created a new project with Angular 6, it automatically created this scripts in package.json

  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }

With that setup, you can do:

  • npm start which calls ng serve from local install.
  • npm build which calls ng build
  • npm test which calls ng test
  • npm run lint which calles ng lint
  • npm run e2e ...

nngo avatar Oct 03 '18 15:10 nngo

i think the only solution is to have installed Angular/cli local instead of global.

saeedkhan-github avatar Mar 24 '19 18:03 saeedkhan-github

Another option with npx bundled these days is to run

npx ng serve

and it will pick up the locally installed version.

almereyda avatar Apr 03 '19 18:04 almereyda

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.