Apache Cordova is a top level project of the Apache Software Foundation (ASF). What Apache Cordova does is, it allows you to build native mobile apps using HTML, CSS and JavaScript. This tutorial is going to show you how-to install Apache Cordova’s command-line interface (CLI). The CLI allows you to create new apps, build apps on different platforms, and run the apps on real devices or within emulators.

Before we can install the Cordova CLI, we will need to install the prerequisites: NodeJS, NPM and Git. So let’s get started!

Installing NodeJS

Run the following command to install NodeJS:

sudo apt-get install nodejs

If that doesn’t work, you can install NodeJS through a PPA repository:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

Okay, let’s check to make sure NodeJS is now installed:

nodejs -v

You should get a result like this:


Install NPM

To install NPM, simply run the following command:

sudo apt-get install npm

To make sure NPM is installed, run:

npm -v

The result should look like:


Install Git

Cordova uses Git in the background to download assets when creating a new project. I have created a Cordova project without Git installed and assets were still downloaded, but let’s be safe. Execute the following command:

sudo apt-get install git

Install Apache Cordova

We will use Node Packaged Modules (NPM) to install Apache Cordova.

sudo npm install -g cordova

That’s it! Let’s make sure it’s installed and to check the version:

cordova -v

Which should give a result like this:


Creating Your First Cordova Project

Now let’s take a moment to quickly go over creating your first Apache Cordova app project. To create your app, use the following command:

cordova create

Where <folder> is the folder where the source will be held – the folder should not already exist, <id> is the reverse domain-style identifier, and <name> is the application’s display title.

You might encounter the following error:

/usr/bin/env: node: No such file or directory

This is because some Linux distributions installs NodeJS as nodejs and not node. To fix this, run the following:

ln -s /usr/bin/nodejs /usr/bin/node

To add platforms, we will need to switch to the app’s folder:


Where <folder> is the folder where the source is held.

Now that we are in the folder, we can add platforms like so:

cordova platform add

Where <platform> is the platform you want to add. Platforms include: ios, amazon-fireos, android, blackberry10, firefoxos, wp8, and windows8. For wp8 and windows8, you should be on a Windows machine. If you try to add a Windows platform, you will encounter the following:

Downloading cordova library for wp8… Download complete Checking wp8 requirements… Requirements check failed: ERROR: Cordova tooling for Windows Phone requires a Windows OS with the ‘msbuild’ command in the PATH environment variable as well as having .NET Framework 4.0 (from WP SDK’s)

Once you are happy and ready to build your project, make sure you are in the project folder and run the following:

cordova build

To build the project for specific platforms, use the following example command:

cordova build

Where <platform> is the platform.

That’s it! This tutorial just helped you install NodeJS, NPM, Git and Apache Cordova, plus showed you how-to get started building your first app.