How to Install and Setup Angular CLI
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
$ sudo node -v
$ sudo npm --version
$ 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
OS: linux x64
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>
$ 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:
β βββ app.e2e-spec.ts
β βββ app.po.ts
β βββ tsconfig.e2e.json
β βββ 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
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:
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.