This week we'll begin creating Angular applications using the Angular CLI tool. CLI stands for "Command Line Interface" and refers to tools used directly from the command line.
Angular CLI allows us to quickly scaffold entire projects with boilerplate code already in place, and to generate new portions of projects (like components, services, and pipes) simply by executing specific commands in the terminal. This lesson will walk through how to install Angular CLI, and discuss a known issue you may encounter. Let's get started!
Angular CLI tool can be installed with npm. It requires Node 4 or higher and npm 3 or higher.
You were already prompted to install at the beginning of this course. You can confirm your versions are correct by following the instructions available in the Installing Node.js lesson from this course's pre-work. Or, you may visit this lesson to install Node at this time, if you haven't already.
As depicted on the Angular CLI homepage we can install the package with one simple command:
$ npm install -g @angular/[email protected]
To check that Angular CLI has been properly downloaded use the command
$ ng -v. This command should return the following output:
_ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | | / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | | /_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___| |___/ Angular CLI: 1.6.5 Node: 8.8.1 OS: darwin x64 Angular: ...
You may receive an error that looks like this:
$ npm install -g @angular/[email protected] npm ERR! cb() never called!
At the time of this writing, this appears to be a known issue with npm. As mentioned in the issue discussion, updating node should resolve the error.
On a Mac, you should be able to upgrade node through Homebrew using the following command:
$ brew upgrade node
On a Windows or Linux machine (or a Mac that doesn't use Homebrew), you can simply return to the Node.js Download Page and select the latest version for your particular operating system. Running this installer should override your current (older) version of Node.
Now that we have the necessary tools, we'll create a new project using Angular CLI.