Skip to main content

Installing Cordova on Ubuntu 16.04 without Android Studio

Apache Cordova is a platform to build mobile applications using JavaScript, HTML5 and CSS.

When I was trying to install cordova for creating an android application on my Ubuntu 16.04 I was facing lot of versioning and dependency problems. So in this post I will be discussing about all those issues and the solution that worked for me. All the steps are via command line and so no android studio. I don't want to install GB's of files to just use sdk.
  • Install latest version of node and npm
  • Install Cordova
  • Install android SDK (Command line)
  • Setting environment variables
  • Creating android plaform
  • Creating and running first app
Installing latest version of nodejs
By default ubuntu 16.04 has a stable version of nodejs added in its own repository. So to install latest version from Ubuntu itself you can simply use apt commad as follows.
$ sudo apt update
$ sudo apt install nodejs
But when I was using this version (4.2.6 is the latest stable version available when I was trying) I got some dependency error while trying to install Cordova. So I forced to add 3rd party ppa to get the latest version of nodejs. But the problem is I had some other project which uses this version of nodejs which is really mandatory.
I found a solution for this by using NVM (Node Version Manager). Using nvm you can install as many version of nodejs you want and switch it from version to version conveniently.
Installing nvm on ubuntu 16.04
$ sudo apt install build-essential libssl-dev
$ sudo apt install curl
$ sudo apt install git
$ curl | bash
Note: In the above url v0.31.0 is the nvm version and this is the latest version available when I was installing.
Close and open the terminal to use nvm (to refresh env) and check the nvm version using following command
$ nvm --version
To install any version of nodejs
$ nvm install 8.1
The above command will install latest build available under nodejs version 8.1. To install the latest version of nodejs available in the repository
$ nvm install node
To list all the installed nodejs versions
$ nvm ls
To use a version
$ nvm use 4.6
Note: 4.6 is the version number
Done, Now you have installed Nodejs!
Installing Cordova
To install cordova you can simply use the npm command and rest all will be taken care.
$ npm install cordova
Don't use sudo when you are using nodejs via nvm, if the installation fails and requires permission. There is a hack to make your current nodejs available for root using following command
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
Note: The above command is copying the current version, so at any time in future you switched to another version and that requires sudo, re-run the above command again.
Good! Now you have successfully installed cordova.
Installing android SDK
Downloading sdkmanager:
Goto and scroll down to see "Get Just command line tools" portion and select the sdk download link for linux. Once downloaded extract it to your home directory.
Installing Java if not installed before
$ sudo apt update
$ sudo apt install default-jre
$ sudo apt install default-jdk
Updating sdk with required platform-tools
$ cd /home/<user-name>/sdk/tools
$ ./android update sdk --no-ui
Wait for update to finish, you will see "Done!" message once update is completed. Refer this documentation for how to use command line sdk-manager
Install gradle and adb
$ sudo apt install gradle
$ sudo apt install adb
Setting up cordova environment for Android application
$ cd
$ vi .bashrc
and add the following environment variables at the end of the file
# Cordova setup
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/;
export PATH=$PATH:"/home/<user-name>/sdk/platform-tools/";
export PATH=$PATH:"/home/<user-name>/sdk/tools/";
export PATH=$PATH:"/home/<user-name>/sdk/tools/bin/";
Note: <user-name> should be replaced with your Ubuntu user-name. And I am assuming you extracted that sdk zip file to your home directory with name sdk.
Your installed version of java might be different and so make sure you are setting the correct path for JAVA_HOME.
Even after giving correct path for JAVA_HOME I had an issue saying Java path is missing. Basically your java and javac command should point to the same version. You can use following command to choose the required default javac.
$ sudo update-alternatives --config javac
Configuring sdkmanager with dependency:
Install the target android platform
sdkmanager "platforms;android-26"
Creating and testing your first Cordova app
$ cordova create hello com.example.hello HelloWorld
$ cd hello
$ cordova add platform android
Connect your android device ( I am assuming you have respective driver installed and adb was able to detect your device)
Test your first app
$ cordova run android
If you see the app installed and opened in your mobile. Congrats! you have successfully installed and used Cordova in your Ubuntu.
If you have faced any other issues and found solution for that, please add it in the comments section so that it can help others.



Popular posts from this blog

Git and Github useful commands

Working on a personal forked repository Most of the time when you are working in an organisation who uses git, you will be requested to fork the project and create pull for your feature or bug fixes (Most of the open source contribution in git will be happening like this).

In this note I will let you know some useful git commands which will be very helpful for you in your day to day life with git. I am not going to explain any git technical terms. I am assuming you already know about it or all those terms are linked to a proper source for more information.
Lets start. You can fork any github project by clicking the fork icon on the top right of a repository.  git clone<your-github-id>/Project.git - to clone your forked Project (personal repo)cd Project/ - get into your repositorygit fetch origin - will fetch all the details/indexes (branches and commits) from remote origin but will not apply.git branch - is used to check all the available branches and current work…

Make use of JavaScript console methods

When I say JavaScript console methods, the one and only thing that hit most of our mind is console.log() and we use it a lot and only that some might be familiar with error() and debug(). Did you ever think of checking if there are any other methods available in console other than log? Most of us don't do that, but knowing those methods might have saved lot of our development time. In this post I will show you some of the console methods which will be very useful in our day to day coding.
Log based on conditionconsole.assert(assertion, log_message); To print something on the console only if the assertion failed - assertion can be any expression which returns a boolean.
Note: In chrome this log will print as an error with message saying "Assertion failed:" with the log_message passed. In FireFox its a normal log message.
Log number of occurrence console.count([label]); If we want to count something, it may be a click, may be a callback, or event triggers. We don't …

My First Post

After lot of thinking and research me too started a blog finally to share my knowledge :-).

Not everybody know everything but also everybody else don't know what we know. So lets share and gain knowledge with Win Win approach.