This tutorial will help you to install Angular.js on your macOS operating system via command line. You must need to install Homebrew package manager on your macOS.
Step 1 – Prerequsities
Let’s start the installation of Node.js on your macOS system using Homebrew. So first update the Homebrew package manager index. Then you can install Node.js package in your MacOS system using the following command:
brew update brew install node
You have successfully installed Node.js on your system. Execute below command on the terminal to view the installed Node.js version info.
node -v v12.4.0
Step 2 – Install Angular/CLI on macOS
After installing the Node.js and npm on your system, use the following commands to install the Angular CLI tool on your system globally.
npm install -g @angular/cli
This command will install the latest available Angular CLI version on your macOS system. If you need any other Angular version on your macOS use one of the following commands as per required version.
npm install -g @angular/[email protected]6 #Angular 6 npm install -g @angular/[email protected]7 #Angular 7 npm install -g @angular/[email protected]8 #Angular 8 npm install -g @angular/[email protected]9 #Angular 9
Using the -g above command will install the Angular CLI tool globally. So it will be accessible to all users and applications on the system. Angular CLI provides a command ng
used for command-line operations. Let’s check the installed version of ng on your system.
ng --version
Step 3 – Create New Angular Application
Now, create a new application named hello-angular4 using the Angular CLI tools. Execute the commands to do this:
ng new hello-angular4
Output:
... ... added 1011 packages from 1041 contributors and audited 19005 packages in 55.774s found 0 vulnerabilities Successfully initialized git.
This will create a directory named hello-angular4 in your current directory, and create an application.
Step 4 – Serve Angular Application
Your basic Angular application is ready to serve. Change directory to hello-angular4 and run your Angular application using ng serve command.
cd hello-angular4 ng serve
You can access your angular application on localhost port 4200, Which is the default host and port used by Angular application.
- http://localhost:4200
You can change host and port for running Angular application by providing –host and –port command line arguments.
ng serve --host 0.0.0.0 --port 8080
The IP address 0.0.0.0 listens on all interfaces and publically accessible.
3 Comments
or use:
brew install angular-cli
I have been trying to angular cli installed on mac os but it keeps coming up with command not found: ng. Below are notes from what I followed in this guide and it seems like everything should have loaded but I still get command not found. This seems like it could be more of an issue with npm or something but I don’t know how to fix it. Do you have any steps for how to resolve this so that ng will run?
@Macs-Mac ~ % brew -v
Homebrew 2.5.0
Homebrew/homebrew-core (git revision d1c83d; last commit 2020-09-12)
@Macs-Mac ~ % node -v
v12.18.3
@Macs-Mac ~ % npm install -g @angular/cli
npm WARN deprecated [email protected].2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: this library is no longer supported
/Users//npm-global/bin/ng -> /Users//npm-global/lib/node_modules/@angular/cli/bin/ng
> @angular/[email protected] postinstall /Users//npm-global/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js
+ @angular/[email protected]
updated 1 package in 8.494s
@Macs-Mac ~ % ng -v
zsh: command not found: ng
@Macs-Mac ~ % cd /Users//npm-global/lib/node_modules/@angular/cli/bin
@Macs-Mac bin % ls
ng postinstall
download the latests version