Install different versions of Angular CLI

The solution is to simply use a local installation of the angular CLI. Local to the project, instead of global to the whole computer.

That is, even if you have Angular CLI installed on your computer, globally, you are going to install it locally to the project.

  1. You enter the folder of your project, the root, where you have the package.json file
  2. Install the Angular CLI

npm install -D @angular/cli

Notice that instead of “-g” we have put “-D” to indicate that it is NOT a global installation and to indicate that it is a development dependency.

Once the dependency has been installed locally to the project, instead of doing “ng serve” or whatever command (which would cause the global Angular CLI installation you have to run), you can run it as follows:

Option 1) Using the path where the file is:

node_modules/.bin/ng

Option 2) Creating an npm script If you know how, you can create an npm script, in package.json, that runs the commands you need. When you have the npm script, it will always run the commands with the locally installed versions. That way you can do something like “npm run ng:serve” to run the Angular CLI development server in the local version.

The npm script might look something like this:

“scripts”: { “ng:serve”: “ng serve”,

If you have a problem, you can make sure that the program is running in the local version, placing the path:

“scripts”: { “ng:serve”: “./node_modules/.bin/ng serve”,

Loading Facebook Comments ...
Loading Disqus Comments ...