How to Install and Setup Angular CLI
Posted on July 11th, 2020
Angular is an open-source framework for your web applications. It is one of the ambitious and fast-growing platforms to develop scalable and fast applications for cross platforms, such as web, native mobile, mobile web, and more. The Angular framework contains assets, libraries, and utilities. In this tutorial, we will check how to install and setup angular CLI on CentOS or RHEL 7.
Angular CLI is the command-line interface for the Angular framework; thus, it is called Angular CLI. The Angular CLI includes packages, libraries, browser links, and more. Angular CLI uses Webpack, but there is no need for you to know how Webpack works and the configuration of the same. The Angular CLI helps you to automate the development workflow. Angular CLI offers different features, and some of them are:
- It helps you to create a new application in the Angular framework.
- It helps to preview your application with the help of the development server running on it.
- It helps you to add features to your existing application running with an Angular framework.
- It helps you to run different unit tests for your application.
- It helps you to run different end-to-end (E2E) tests for your application.
- It helps you to build applications and deploy them to production.
In this knowledgebase, you learn how to install and setup Angular CLI on CentOS or RHEL servers. For the same, follow the below steps:
1) Install Node.js
Before the installation of Angular CLI, your system should have Node.js 6.9.0 and npm 3.0.0 or higher installed. Download and install Node.js by using the following commands.
$ sudo curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash - $ sudo yum install nodejs
After the installation, check if the installation was successful by using the following command.
$ sudo node --version or $ sudo node -v $ sudo npm --version or $ sudo npm -v
The above commands display the version of Node.js and npm. If TypeScript is not available on the server, run the following npm command to install TypeScript.
$ sudo npm install -g [email protected]
2) Install Angular CLI
After the successful installation of Node.js and npm, run the following command to install the Angular CLI tool on your server.
$ sudo npm install -g @angular/cli
The -g command installs the Angular CLI tool globally on your system. That makes it easy for all the users and applications on the system to use the tool. The successful installation of Angular CLI, the ‘ng’ command installs globally on your system.
After the installation, check the version of Angular CLI by using the following command.
$ sudo ng --version
The above command should have an output similar to the one shown below:
_ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | | / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | | /_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___| |___/ Angular CLI: 8.0.4 Node: 12.4.0 OS: linux x64 Angular: ... Package Version ------------------------------------------------------ @angular-devkit/architect 0.800.4 @angular-devkit/core 8.0.4 @angular-devkit/schematics 8.0.4 @schematics/angular 8.0.4 @schematics/update 0.800.4
How to Create New Angular Application
Use any of the two methods to create a new Angular application using the Angular CLI tool. The methods are:
The ‘ng init’ command helps you to create a new application in the current directory.
The ‘ng new’ command helps you to create a new directory, and then this command executes the ‘ng init’ inside the director created.
So both these methods help you to create a new application, but the ‘ng new’ creates a new directory for you. If you have not created any directory yet, then run the following command to create a new Angular application or project.
$ sudo ng new <Application_name>
For example,
$ sudo ng new hello-angular
This above command does the following:
- Creates a new directory named ‘hello-angular’.
- Creates all the source files and directory for your new Angular application named ‘hello-angular’.
- Installation of npm dependencies.
- Configure the TypeScript.
- Configure the ‘Karma’ unit test runner.
- Configure the ‘Protractor’ end-to-end test framework.
- It Creates environment files with default settings.
This above command should have an output similar to the one shown below:
... ... added 1011 packages from 1041 contributors and audited 19005 packages in 55.774s found 0 vulnerabilities Successfully initialized git.
After that, you have a working application, and the directory structure should look similar to the one shown below:
. ├── README.md ├── e2e │ ├── app.e2e-spec.ts │ ├── app.po.ts │ └── tsconfig.e2e.json ├── karma.conf.js ├── package.json ├── protractor.conf.js ├── src │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ └── app.module.ts │ ├── assets │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ ├── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── typings.d.ts ├── tsconfig.json └── tslint.json
Save Angular Application
Now, the application is ready to serve. To run the application, change the directory to the newly created directory and then run the ng command to run the Angular application.
$ sudo cd hello-angular $ sudo ng serve
After that, to access your Angular application on localhost port 4200, hit the following URL in any wen browser:
http://localhost:4200
If you want to change the host and port number for your application, run the following command.
$ sudo ng serve --host <IP_address> --port <port_number>
We hope this knowledge base was helpful to you. Please comment below for any questions or queries. If you are an InterServer customer, please reach out to our support team for further help.