How to Install Angular CLI on Linux

Angular is an open-source, popular and highly-extensible front-end application development framework, used for building mobile and web applications using TypeScript/JavaScript and other common languages. Angular is an umbrella term for all Angular versions that come after AngularJS (or Angular version 1.0) including Angular 2, and Angular 4.

Angular is well suited for building small to large scale applications from scratch. One of the key components of the Angular platform to aid application development is the Angular CLI utility – it is a simple and easy-to-use command-line tool used to create, manage, build and test Angular applications.

Read Also: How to Run Angular Apps Using Angular CLI and PM2

In this article, we will explain how to install Angular command-line tool on a Linux system and learn some basic examples of this tool.

Installing Node.js in Linux

To install Angular CLI, you need to have the latest version of Node.js and NPM installed on your Linux system.

Install Node.js on Ubuntu

$ sudo curl -sL | sudo -E bash - [for Node.js version 12]
$ sudo curl -sL | sudo -E bash - [for Node.js version 11]
$ sudo curl -sL | sudo -E bash - [for Node.js version 10]
$ sudo apt install -y nodejs

Install Node.js on Debian

# curl -sL | bash - [for Node.js version 12]
# curl -sL | bash - [for Node.js version 11]
# curl -sL | bash - [for Node.js version 10]
# apt install -y nodejs

Install Node.js on CentOS/RHEL & Fedora

# curl -sL | bash - [for Node.js version 12]
# curl -sL | bash - [for Node.js version 11]
# curl -sL | bash - [for Node.js version 10]
# yum -y install nodejs
# dnf -y install nodejs [On RHEL 8 and Fedora 22+ versions]

Also, to compile and install native add-ons from NPM you may need to install development tools on your system as follows.

$ sudo apt install -y build-essential  [On Debian/Ubuntu]
# yum install gcc-c++ make             [On CentOS/RHEL]
# dnf install gcc-c++ make             [On RHEL 8/Fedora 22+]

Installing Angular CLI in Linux

Once you have Node.js and NPM installed, as shown above, you can install Angular CLI using the npm package manager as follows (the -g flag means to install the tool system-wide to be used by all system users).

# npm install -g @angular/cli
$ sudo npm install -g @angular/cli
Install Angular CLI in Linux

Install Angular CLI in Linux

You can launch the Angular CLI using the ng executable which should now be installed on your system. Run the following command to check the version of Angular CLI installed.

# ng --version
Check Version of ng

Check Version of ng

Creating an Angular Project Using Angular CLI

In this section, we will show how to create, build, and serve a new, basic Angular project. First, move into the webroot directory of your server, then initialize a new Angular application as follows (remember to follow the prompts):

# cd /var/www/html/
# ng new tecmint-app			#as root
$ sudo ng new tecmint-app		#non-root user
Create New Angular App

Create New Angular App

Next, move into the application directory which has just been created and serve application as shown.

# cd tecmint-app
# ls 			#list project files
# ng serve
Serve Angular App

Serve Angular App

Before you can access your new app from a web browser, if you have a firewall service running, you need to open port 4200 in the firewall configuration as shown.

---------- On CentOS/RHEL/Fedora ---------- 
# firewall-cmd --permanent --zone=public --add-port=4200/tcp 
# firewall-cmd --reload

---------- On Ubuntu/Debian ----------
$ sudo ufw allow 4200/tcp
$ sudo ufw reload

Now you can open a web browser and navigate using the the following address to see the new app run as shown in the following screenshot.

Access Your New Angular App

Access Your New Angular App

Note: If you use the command ng serve to build an application and serve it locally, as shown above, the server automatically rebuilds the app and reloads the web page(s) when you change any of the source files.

For more information concerning the ng tool, run the following command.

# ng help

The Angular CLI Homepage:

In this article, we have shown how to install Angular CLI on different Linux distributions. We also covered how to build, compile and server a basic Angular application on a development server. For any queries or thoughts, you want to share with us, use the feedback form below.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

2 Responses

  1. William Best says:

    You should use Node Version Manager instead. That way you can switch to different versions of node easily.

    curl | bash
    nvm install 10.16

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.