Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Ubuntu 13.04, json fails to do anything once installed #56

Closed
craigwblake opened this issue Aug 8, 2013 · 11 comments
Closed

On Ubuntu 13.04, json fails to do anything once installed #56

craigwblake opened this issue Aug 8, 2013 · 11 comments

Comments

@craigwblake
Copy link

Installation completes normally, 'json' program is present but no matter what I run there is no output

$ json --version
$

$ echo '{"foo":"bar"}' | json
$

@trentm
Copy link
Owner

trentm commented Aug 8, 2013

@craigwblake I don't have enough to go on here. How did you install this? which json Can you show me the content of the json script file that is running?

@craigwblake
Copy link
Author

Sure, I'll share what I can. I run "apt-get install node" to install node then ran "npm install -g jsontool" per the instructions on the main page. That all completed without error, and it installed the json command in "/usr/local/bin/json"

Here is the content of the file in that location:

#!/usr/bin/env node
//
// json -- a 'json' command for massaging JSON on the command line
//
// See <https://github.com/trentm/json>.
//

var VERSION = "6.0.0";

var p = console.warn;
var util = require('util');
var assert = require('assert');

... most of file ellided because have enough here to confirm this is *my* json tool :) ...

    };
  }

  main(process.argv);
}

@trentm
Copy link
Owner

trentm commented Aug 8, 2013

@craigwblake Thanks. Okay, what is the output of:

which node

`which node` --version

`which node` /usr/local/bin/json --version

I've not seen that behaviour (calling json --version exiting showing nothing). I've also never used the apt-provided node on Ubuntu.

@craigwblake
Copy link
Author

Well I ran that and it didn't work I looked into and found out that on Ubuntu the Node.js binary is installed as 'nodejs'.

That certainly explains why it wasn't working, but it's definitely not obvious from the lack of output. Maybe it's worth checking for 'nodejs' as the executable if 'node' fails in your script?

@craigwblake
Copy link
Author

Also, for reference there is a different 'node' binary on Ubuntu (which is why nodejs could not use the name) which when run outputs nothing. Quite an annoying coincidence that made the problem non-obvious.

@trentm
Copy link
Owner

trentm commented Aug 8, 2013

What?! That's crazy. I don't know a reasonable way to deal with that on json's end. There must be many node.js-based command line tools that have this same issue.

A little bit of searching turned this up: http://askubuntu.com/questions/235655/node-js-conflicts-sbin-node-vs-usr-bin-node Specifically:

sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs

# Confirm it worked
node --version       # v0.10.13
ls -la `which node`  # ... /usr/bin/node -> /etc/alternatives/node

Is that a reasonable workaround for you? I'm not familiar with current and past Ubuntu node.js packaging naming.

@craigwblake
Copy link
Author

I tried but it still didn't link the 'nodejs' binary to 'node'. Oh well, I manually linked it so it works now. Perhaps it would be sufficient for a warning for Ubuntu users on your installation instructions?

@trentm
Copy link
Owner

trentm commented Aug 8, 2013

@craigwblake I got a response from @isaacs:

The answer is that this is a known bug in debian-stable. He should either: a) install from source, b) install from the binary tarballs on http://nodejs.org/ or c) use chrislea's PPA https://launchpad.net/~chris-lea/+archive/node.js/

it is my understanding that Debian is changing this moving forward.
so future versions will have the "nodejs" package install a binary called "node", and have it conflict with the "ham-node" package

@trentm
Copy link
Owner

trentm commented Aug 9, 2013

README.md warning added in the install section. Thanks!

@stevebest
Copy link

Instead of #!/usr/bin/env node, try this

#!/usr/bin/env sh
':' //; exec "$(command -v nodejs || command -v node)" "$0" "$@"

Say whaaaat?

It's a polyglot script. sh sees it as a shell script that tries to exec itself using either nodejs or node; node sees it as a no-op and executes everything below. Everyone is happy!

Credit goes to guys on stackexchange.

@stevebest
Copy link

See #74.

The warnings in docs and install scripts are probably no longer required with this hack and could be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants