Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install angular-cli "locally" #5955

Closed
jdang67 opened this issue Apr 13, 2017 · 20 comments
Closed

How to install angular-cli "locally" #5955

jdang67 opened this issue Apr 13, 2017 · 20 comments

Comments

@jdang67
Copy link

jdang67 commented Apr 13, 2017

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 angular-cli@1.0.0.
We just want able to work on both new and old angular-cli.

thanks
Jdang

@hansl
Copy link
Contributor

hansl commented Apr 13, 2017

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.

@jdang67
Copy link
Author

jdang67 commented Apr 13, 2017

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

@raDiesle
Copy link

raDiesle commented Apr 24, 2017

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 ?

@squadwuschel
Copy link

squadwuschel commented May 19, 2017

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

@jdang67
Copy link
Author

jdang67 commented May 19, 2017

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.

@raDiesle
Copy link

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

@jdang67
Copy link
Author

jdang67 commented May 21, 2017

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

Jdang

@raDiesle
Copy link

raDiesle commented May 21, 2017 via email

@jdang67
Copy link
Author

jdang67 commented May 22, 2017

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.

@akashraom
Copy link

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?

@darrhal
Copy link

darrhal commented Aug 4, 2017

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.

@jswagger
Copy link

jswagger commented Nov 6, 2017

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

@raghulrajnkl
Copy link

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

@chebotarevmichael
Copy link

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

@mnicic
Copy link

mnicic commented Jun 12, 2018

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.

@fizxmike
Copy link

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

@nngo
Copy link

nngo commented Oct 3, 2018

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 ...

@saeedkhan-github
Copy link

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

@almereyda
Copy link

Another option with npx bundled these days is to run

npx ng serve

and it will pick up the locally installed version.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests