Cordova throws syntax error when trying to add platform

I'm trying to install Cordova and Ionic Framework on a Ubuntu server. I already used Node.js on it, so simply ran:

sudo npm install -g cordova

Then I cloned a sample project from GitHub

sudo git clone https://github.com/driftyco/ionic-weather.git

I entered the directory and tried to add the iOS platform library in order to build it:

cd ionic-weather
sudo cordova platform add ios

However it throws the following error:

Creating ios project...
/home/benedict/.cordova/lib/ios/cordova/3.4.0/bin/create: 33: /home/benedict/.cordova/lib/ios/cordova/3.4.0/bin/create: Syntax error: "(" unexpected
Error: /home/benedict/.cordova/lib/ios/cordova/3.4.0/bin/create: Command failed with exit code 2
    at ChildProcess.whenDone (/usr/lib/node_modules/cordova/src/superspawn.js:112:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)

I've tried reinstalling Cordova in case something got corrupted, but no luck. I can't seem to find anyone else with this issue either so I'm kinda stuck. Any ideas?

Your problem is that your trying to build the app on a machine that doesnt have Mac OS installed. In order to add IOS platform you need to run this command on a mac.

Check the Prerequisites here: http://docs.phonegap.com/en/3.0.0/guide_cli_index.md.html

This turned out to be a combination of several problems:

  1. Ant is a required dependency, although it's not documented as a dependency as far as I can tell from any of the install guides the ionic guide or cordova guide point to. In fact I found this out by digging around SO and a few other dark corners of the internet
  2. JDK must also be installed. (not just JRE)
  3. 2 folders have to be added to the path (for Android anyways).

Ant

This can be installed via sudo apt-get install ant.

jdk

sudo update-alternatives --config java

first, you can find out if you have jdk by running `sudo update-alternatives --get-selections | grep ^java

if you already have the jdk, you can update your jre to the jdk version using sudo update-alternatives --config java

if not, then install jdk (not just the jre), using sudo apt-get install openjdk-7-jdk

Path setting in ~/.bashrc

$ cd ~
$ sudo vi .bashrc

at the bottom, before the PATH= add the path to the bundle folders for both platform-tools folder and the tools folder under the sdk folder. Several of the guides only mention the platform-tools folder.

The guide specifically mentions ios can't be installed on Windows, but strangely leaves out Linux. This may be an oversight, but I can't be sure. There was some indication in the ionic guides that ios emulation could be done on linux, even though actual development could only be done on OSx.

the ios platform requires xcode 4.5 with cordova, which needs OSx 10.7 you basically can't add the ios platform tools on Windows or Linux. Unfortunately cordova and ionic both seem to forget Linux exists, and therefore the docs imply this will run on Linux when they note inoperability on Windows but say nothing about Linux.