4

I've just started working with Angular and with Angular-CLI and I've seen that, according to the documentation, I need to install $ npm install -g @angular/cli with the -g (global) flag.

Once the package is installed, the default path to it in Angular CLI will be something like C:\Users\{user}\AppData\Roaming\npm\node_modules\@angular\cli.

Now i want to install Angular CLI to something like this path D:\npm\node_modules\@angular\cli.

I tried D:\>npm install @angular/cli

enter image description here

Is it possible? Your help will be appreciated.

Sumesh TG
  • 2,557
  • 2
  • 15
  • 29
  • 1
    See https://stackoverflow.com/questions/19874582/change-default-global-installation-directory-for-node-js-modules-in-windows. This is not an Angular problem. – Wandrille Mar 14 '19 at 12:16

3 Answers3

4

As per npm docs you can use --prefix options to change the installation directory:

Step 1:

Create D:\angular_cli\ folder if it does not exist

Step 2:

npm install --prefix D:\angular_cli\ @angular/cli

Step 3:

Append D:\angular_cli\node_modules\.bin to path environment variable

jumping_monkey
  • 5,941
  • 2
  • 43
  • 58
  • Thanks for your answer this helps as expected. Could you explain how to add this to path? `ng -v` and `ng new` are not working as expected. – Sumesh TG Mar 14 '19 at 12:50
  • 1
    It, depend on your os version. If it win 8 or higher, that should help - `setx path "%path%;d:\directoryPath"`. And if an answer was helpful, can you submit it as a correct answer? – Anton Gorshenin Mar 15 '19 at 10:25
2

We can use --prefix options to change the installation directory.

So for in this case it will be:

Step 1 : create a folder angular_cli in D drive

Step 2 : run this command after navigating to d drive

npm install --prefix D:\angular_cli\ @angular/cli

As a pre requirements, D:\angular_cli\ folder must be exist

And append this path to path environment variable

D:\angular_cli
Sumesh TG
  • 2,557
  • 2
  • 15
  • 29
1

I don't know what are doing with just installing angular-cli some custom location but yes, it's possible you just need to remove -g flag from the command of installation like below.

Step1: Navigate to your desired location of installation.

c:\>cd D:\npm\node_modules\@angular\cli

Step2: Install the angular-cli

D:\npm\node_modules\@angular\cli> npm install @angular/cli

Hope this will help!

TheParam
  • 10,113
  • 4
  • 40
  • 51