Adding Platform in Apache Cordova does not work

I am installing Apache Cordova on Ubuntu 13.10, following these instructions: http://cordova.apache.org/docs/en/3.5.0//guide_cli_index.md.html#The%20Command-Line%20Interface

I got stuck on the section "Add Platforms":

$ cordova platforms ls

Installed platforms: 
Available platforms: amazon-fireos, android, blackberry10, firefoxos, ubuntu

looks like Ubuntu is available. So I proceed.

$ cordova platform add ubuntu
Checking ubuntu requirements...
Running "dpkg-query -Wf'${db:Status-abbrev}' cmake debhelper libx11-dev libicu-dev pkg-config qtbase5-dev qtchooser qtdeclarative5-dev qtfeedback5-dev qtlocation5-dev qtmultimedia5-dev qtpim5-dev qtsensors5-dev qtsystems5-dev 2>/dev/null | grep -q '^i'" (output to follow)

Make sure you have the following packages installed: 
user@host:/opt/lampp/htdocs/hello$ 

looks already strange, since it warns me to install packages given an empty list.

$ cordova build
No platforms added to this project. Please use `cordova platform add <platform>`.

... and it did not work.

$ cordova platforms ls

Installed platforms: 
Available platforms: amazon-fireos, android, blackberry10, firefoxos, ubuntu

looks like before.

Any ideas?


supplement:

with

$ cordova -d platform add ubuntu

I get the following:

CordovaError: Make sure you have the following packages installed: 
at /usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/metadata/ubuntu_parser.js:56:22
at /usr/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/shelljs/shell.js:1727:7
at ChildProcess.exithandler (child_process.js:651:7)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:755:16)
at Socket.<anonymous> (child_process.js:968:11)
at Socket.emit (events.js:95:17)
at Pipe.close (net.js:465:12)

supplement 2:

Ok, I added all missing libraries by sudo apt-get install ......

Now I get this:

$ cordova -d platform add ubuntu
cordova library for "ubuntu" already exists. No need to download. Continuing.
Checking if platform "ubuntu" passes minimum requirements...
Checking ubuntu requirements...
Running "dpkg-query -Wf'${db:Status-abbrev}' cmake debhelper libx11-dev libicu-dev pkg-config qtbase5-dev qtchooser qtdeclarative5-dev qtfeedback5-dev qtlocation5-dev qtmultimedia5-dev qtpim5-dev qtsensors5-dev qtsystems5-dev 2>/dev/null | grep -q '^i'" (output to follow)

Creating ubuntu project...
Running command: /home/user/.cordova/lib/ubuntu/cordova/3.5.0/bin/create /opt/lampp/htdocs/hello/platforms/ubuntu com.example.hello HelloWorld
Shelljs module was not found, running 'npm install'.....
ERROR : running 'npm install' is npm installed? Error: Command failed: npm WARN package.json cordova-ubuntu@0.0.0 No README data
npm ERR! Error: Attempt to unlock shelljs@0.2.6, which hasn't been locked
npm ERR!     at unlock (/usr/lib/node_modules/npm/lib/utils/locker.js:44:11)
npm ERR!     at cb (/usr/lib/node_modules/npm/lib/cache/add-named.js:32:5)
npm ERR!     at /usr/lib/node_modules/npm/lib/cache/add-named.js:41:20
npm ERR!     at /usr/lib/node_modules/npm/lib/utils/locker.js:30:7
npm ERR!     at /usr/lib/node_modules/npm/node_modules/lockfile/lockfile.js:167:38
npm ERR!     at OpenReq.Req.done (/usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:144:5)
npm ERR!     at OpenReq.done (/usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:64:22)
npm ERR!     at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Linux 3.11.0-26-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! cwd /home/user/.cordova/lib/ubuntu/cordova/3.5.0/bin
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! Error: Attempt to unlock elementtree@*, which hasn't been locked
npm ERR!     at unlock (/usr/lib/node_modules/npm/lib/utils/locker.js:44:11)
npm ERR!     at cb (/usr/lib/node_modules/npm/lib/cache/add-named.js:32:5)
npm ERR!     at /usr/lib/node_modules/npm/lib/cache/add-named.js:41:20
npm ERR!     at /usr/lib/node_modules/npm/lib/utils/locker.js:30:7
npm ERR!     at /usr/lib/node_modules/npm/node_modules/lockfile/lockfile.js:167:38
npm ERR!     at OpenReq.Req.done (/usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:144:5)
npm ERR!     at OpenReq.done (/usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:64:22)
npm ERR!     at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

....[several other lines with similar errors].....

Command finished with error code 1: /home/user/.cordova/lib/ubuntu/cordova/3.5.0/bin/create /opt/lampp/htdocs/hello/platforms/ubuntu,com.example.hello,HelloWorld
Error: /home/user/.cordova/lib/ubuntu/cordova/3.5.0/bin/create: Command failed with exit code 1
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:755:16)
at Process.ChildProcess._handle.onexit (child_process.js:822:5)

And yes, npm IS installed

solved by changing the ownership of /home/user/.npm from "root" to "user"

Still, the next problem occurs:

$ cordova build
Running command: /opt/lampp/htdocs/hello/platforms/ubuntu/cordova/build 
/opt/lampp/htdocs/hello/platforms/ubuntu/cordova/check_reqs
Error: missing dependency cmake libicu-dev pkg-config qtbase5-dev qtchooser qtdeclarative5-dev qtfeedback5-dev qtlocation5-dev qtmultimedia5-dev qtpim5-dev qtsensors5-dev qtsystems5-dev
/opt/lampp/htdocs/hello/platforms/ubuntu/cordova/check_reqs FAILED
Error: /opt/lampp/htdocs/hello/platforms/ubuntu/cordova/build: Command failed with exit code 1
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:755:16)
at Process.ChildProcess._handle.onexit (child_process.js:822:5)

And I DO have installed these: cmake libicu-dev pkg-config qtbase5-dev qtchooser qtdeclarative5-dev qtfeedback5-dev qtlocation5-dev qtmultimedia5-dev qtpim5-dev qtsensors5-dev qtsystems5-dev

According to Cordova devs this issue is fixed in the latest version:

https://github.com/apache/cordova-lib/commit/153092f2c235185c7f141979a550779800954a92

Try replace run npm -g explore cordova and replace content of the node_modules/cordova-lib with latest version of the cordova-lib from GitHub.

The error message looks broken but this are the deps you need: cmake libicu-dev pkg-config qtbase5-dev qtchooser qtdeclarative5-dev qtfeedback5-dev qtlocation5-dev qtmultimedia5-dev qtpim5-dev qtsensors5-dev qtsystems5-dev

At least according to this github link: link

You might want to add -d when executing the add platform code for extra debug info like so cordova -d platform add ubuntu

edit:

After question from below: You can call apt-get install <insert package list> to install the packages.

edit2:

Again more info after the comment. Not really sure why it is failing as it seems you do have npm installed right?

You can execute the following from where you are calling the create command, it is not the right place but will probably make it work

npm install shelljs@0.2.6 elementtree colors@0.6.2 optimist@0.6.0 q@2.0.*

When you open up the code for platforms/ubuntu/cordova/check_reps you'll notice something interesting:

var deps = "cmake libicu-dev pkg-config qtbase5-dev qtchooser qtdeclarative5-dev qtfeedback5-dev qtlocation5-dev qtmultimedia5-dev qtpim5-dev qtsensors5-dev qtsystems5-dev";

exec("dpkg-query -Wf'${db:Status-abbrev}\\n' click " + deps, function(error, stdout, stderr)

This will call the following shell command:

dpkg-query -Wf'${db:Status-abbrev}\n' click cmake libicu-dev [and so on...]

I don't know why the "click" package isn't included as part of the deps string, but it's also required and the error message won't tell you that.

I found that installing click did the trick:

sudo apt-get install click

Good luck!

BTW I posted an identical answer here: Build Command in Apache Cordova