How To Install Apache Cordova on Ubuntu 18.04 LTS
This articles will take you through the process of installing Cordova on Ubuntu 18.04 LTS.
Before we begin the installation process, you need to have the following:
- A virtual server running Ubuntu 18.04.
- A non-root user with sudo privileges.
Step 1 – Installing Node.js
The first step is to install the current stable version of Node.js to your virtual machine. Since Node.js is not present in Ubuntu’s default repository, we need to include PPA for node.js for it to install. This can be done by running the command below:
$cd ~ $ curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
You can use nano editor or any other editor of choice to scrutinize the content of the above script:
$ nano nodesource_setup.sh
Alternatively, execute the command below to run the script:
$ sudo bash nodesource_setup.sh
After installing the repository, go ahead and install Node.js by running the command below:
$ sudo apt-get install nodejs -y
To check the version of Node.js installed, execute the command below:
$ nodejs -v
This will give you an output like the one below. The version number may vary depending on the Node.js installed:
Next, run the command below to install Node.js package manager:
$ sudo apt install npm
Execute the command below to verify the version of npm installed:
$ npm -v
This will give you an output similar to the one below:
Step 2 – Installing Cordova Using NPM
The next step is to install Cordova with NPM. Apache Cordova command requires Node.js to run and it’s available on NPM. To install it, run the following command:
$ sudo npm install -g cordova
After installing Cordova, you need to check to verify the version you are using with the command below:
$ cordova --version
The output should look like this:
? May Cordova anonymously report usage statistics to improve the tool over time? Yes Thanks for opting into telemetry to helpus improve cordova. 8.0.0
We can now go ahead and create an app after installing Cordova
Step 3 – Creating An Application With Cordova
Now that you have successfully installed Cordova, you can create your first application .
To do so, run the command below with the name myapp. You can change the name as needed.
$ cordova create myapp
The output should look like this:
Creating a new cordova project.
Now add the platform you want in the application. This process will create the files you need for the corresponding platform.
$cd myapp $ cordova platform add android
The output below will display:
Using cordova-fetch for cordova-android@~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 firstname.lastname@example.org 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 android@~7.0.0 into config.xml file ...
The next thing is to list down the installed platforms that will be required for Cordova application.
$ cordova platform -ls
You should see the output below:
Installedplatforms: android 7.0.0 Availableplatforms: browser ~5.0.1 ios ~4.5.4 osx ~4.0.1 windows ~5.0.0 www ^3.12.0
If you add any platform that you don’t want, you can get rid of it using the command below:
$ cordova platform remove android
Now, you need to build a Cordova application. But before that, make sure that your system fulfils all the requirements needed for your build environment.
$ cordova requirements
After installing these requirements, run the command below to start building your application:
$ cordova build android
Check out these top 3 Linux hosting services
- To end your queries about Top web hosting, simply click on this link.