Before we can install the Cordova CLI, we will need to install the prerequisites: NodeJS, NPM and Git. So let’s get started!
For this tutorial, I’m using Ubuntu 14.04 x64 with 512 MB from DigitalOcean.
DigitalOcean also has a pre-installed NodeJS server, so these steps are not necessary if you choose to get the pre-installed server.
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:
You should get a result like this:
To install NPM, simply run the following command:
sudo apt-get install npm
To make sure NPM is installed, run:
The result should look like:
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:
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:
<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:
<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
<platform> is the platform you want to add. Platforms include: ios, amazon-fireos, android, blackberry10, firefoxos, wp8, and windows8. For
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:
To build the project for specific platforms, use the following example command:
<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.