Local Ionic and Cordova, without sudo

So, all tutorials and documentation on Ionic Framework tells you to install ionic and cordova globally (using “npm -g cordova” and “npm -g ionic”).

That is just so ugly. How am I supposed to use different versions in different project, and what if I don’t have sudo accesss?!

Just installing ionic and cordova locally (skipping the -g parameter) does not work, since ionic and cordova will not find each other. So ionic and cordova must be in your PATH, but again, that will lead to headache when dealing with multiple project with different versions of ionic/cordova.

My solution to this is to start all projects with a Makefile, which keeps track of the PATH for the project, and put the ionic/cordova commands that I use into that Makefile. Something like this:

So, first run “make deps” to install cordova and ionic into your local node_modules/.

Then “make start” to create the project. Note that this make command will actually create the project in a subdirectory and then copy it into the same directory as your Makefile. (The ionic command line does not support “ionic start .” for creating a project in the current directory.)

Now you can “make serve”, or add other ionic commands into your Makefile.