In the world of mobile application development, Apache Cordova stands out as a remarkable framework that enables developers to build mobile apps using HTML, CSS, and JavaScript. This guide is tailored for beginners and will walk you through the process of setting up Cordova on two popular Linux distributions: Ubuntu and Linux Mint. By following these steps, you’ll be well on your way to creating your very own mobile applications.
Prerequisites
Before diving into the installation process, ensure that your system meets the following requirements:
- Ubuntu or Linux Mint operating system
- Node.js installed
- npm (Node Package Manager) installed
Step 1: Install Node.js and NPM
Cordova relies on Node.js and npm. If you haven’t installed them yet, open your terminal and execute the following commands:
sudo apt update
sudo apt install nodejs npm
Instead of installing Debian packages, You can use popular Node Version Manager (NVM) to install Node.js and NPM.
Verify the installation by checking the versions of Node.js and npm:
node --version
npm --version
Step 2: Install Cordova using NPM
With Node.js and npm ready, installing Cordova is straightforward. In your terminal, run:
sudo npm install -g cordova
The -g
flag installs Cordova globally, making it accessible from any directory on your system.
Step 3: Setting Up Your First Cordova Project
Now that Cordova is installed, you can create your first project. Choose a directory where you want your project to be and run:
cordova create hello com.example.hello HelloWorld
This command creates a new Cordova project with the following parameters:
- hello: the directory for your project
- com.example.hello: your project’s package ID
- HelloWorld: the name of your application
Step 4: Add Platforms to Your Cordova Project
Cordova allows you to build your app for various platforms. To add a platform, navigate to your project directory and execute:
cd hello
cordova platform add android
This example adds support for Android. If you’re interested in iOS or other platforms, ensure you have the necessary SDKs installed.
Step 5: Build and Run Your App
To build your Cordova app, run:
cordova build android
This command prepares your app for the Android platform. To run your app on an emulator or an actual device, use:
cordova run android
Ensure your Android device is connected or an emulator is running.
Tips for Successful Cordova Development
- Stay Updated: Regularly update Cordova and the platforms to access new features and bug fixes.
- Explore Plugins: Cordova’s power is in its plugins. Explore available plugins to enhance your app’s functionality.
- Use Version Control: Keep your project under version control with Git or any other system of your choice.
Conclusion
You’ve taken your first steps into the exciting world of mobile app development with Cordova on Ubuntu and Linux Mint. The process, from installation to running your first app, is straightforward, making Cordova an excellent choice for beginners and seasoned developers alike. As you grow more comfortable, experiment with Cordova’s extensive features and plugins to expand your app’s capabilities. Happy coding!
3 Comments
i have error when check version cordova,
usr/local/lib/node_modules/cordova/node_modules/fs-extra/lib/mkdirs/make-dir.js:85
} catch {
^
SyntaxError: Unexpected token {
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInThisContext (vm.js:197:10)
at Module._compile (internal/modules/cjs/loader.js:618:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Module.require (internal/modules/cjs/loader.js:598:17)
at require (internal/modules/cjs/helpers.js:11:18)
what i have to do?
None of this works with 18.04 currently as there isn’t a Cordova package for “bionic”. The title is not accurate
Hi!
Thanks for your tuto.
I’m on Ubuntu 16.04 LTS.
Whwn I finish and check Cordova version, I get :
$ cordova –version —> 4.3.1
$ sudo cordova –version —> 7.1.0
It is less than your version. Is it normal?