How to Install Apache Cordova on Ubuntu 18.04 LTS
In this tutorial, we will learn how to install Cordova on Ubuntu 18.04 LTS (Bionic Beaver).
- A server running Ubuntu 18.04 to your system.
- A non-root user with sudo privileges.
First, you will need to install the latest version of Node.js to your system. By default, the latest version of Node.js is not available in Ubuntu 18.04 default repository. So, you will need to add PPA for node.js to your system.
You can do this with the following command:
sudo apt-get install python-software-properties -y
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
Once the repository is installed, install Node.js using the following command:
sudo apt-get install nodejs -y
Now, install Cordova using the npm command as below:
sudo npm install -g cordova
/usr/bin/cordova -> /usr/lib/node_modules/cordova/bin/cordova + [email protected] updated 1 package in 15.829s
Once the Cordova is installed, you can check the version using the following command:
? May Cordova anonymously report usage statistics to improve the tool over time? Yes Thanks for opting into telemetry to help us improve cordova. 8.0.0
Create Your First App
Cordova is now installed, it's time to create an app using Cordova.
Run the following command to create your first app with name TestApp:
cordova create TestApp
Creating a new cordova project.
Next, change the directory to the TestApp and add the required platform in your application.
cordova platform add android
You should see the following output:
Using cordova-fetch for [email protected]~7.0.0 Adding android project... Creating Cordova project for the Android platform: Path: platforms/android Package: io.cordova.hellocordova Name: HelloCordova Activity: MainActivity Android target: android-26 Subproject Path: CordovaLib Subproject Path: app Android project created with [email protected] Android Studio project detected Android Studio project detected Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project Installing "cordova-plugin-whitelist" for android This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in. Adding cordova-plugin-whitelist to package.json Saved plugin info for "cordova-plugin-whitelist" to config.xml --save flag or autosave detected Saving [email protected]~7.0.0 into config.xml file ...
Next, run the following command to list the installed and available platforms for Cordova application.
cordova platform -ls
Installed platforms: android 7.0.0 Available platforms: browser ~5.0.1 ios ~4.5.4 osx ~4.0.1 windows ~5.0.0 www ^3.12.0
If you want to remove any platform, you can remove it by just running the following command:
cordova platform remove android
Next, you will need to fulfill all the requirements for your build environment. You can do this by running the following command:
Once all the required dependencies are installed successfully, run the following command to build your application:
cordova build android