7

I installed jshint using sudo npm install -g jshint, and it seems to have worked:

$which jshint
/usr/local/bin/jshint

Yet running jshint or its full path equivalent doesn't seem to do anything. It doesn't give an error, either--it just does nothing:

$jshint
$jshint --help
$jshint --verbose
$jshint --debug

$jshint admin.js
$jshint admin.js --verbose
$/usr/local/bin/jshint admin.js

I also tried symlinking nodejs per this answer:

$sudo ln -s /usr/bin/nodejs /usr/bin/node

$jshint admin.js --verbose
$jshint admin.js
$jshint --help
$man jshint
No manual entry for jshint
See 'man 7 undocumented' for help when manual pages are not available.

What am I missing here?

Edit: here's the output from apt-cache policy nodejs npm. I'm just using the standard Ubuntu 14.04 packages, so there's nothing very special about this:

└─>apt-cache policy nodejs npm
nodejs:
  Installed: 0.10.25~dfsg2-2ubuntu1
  Candidate: 0.10.25~dfsg2-2ubuntu1
  Version table:
 *** 0.10.25~dfsg2-2ubuntu1 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
        100 /var/lib/dpkg/status
npm:
  Installed: 1.3.10~dfsg-1
  Candidate: 1.3.10~dfsg-1
  Version table:
 *** 1.3.10~dfsg-1 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
        100 /var/lib/dpkg/status
4
  • What is the output of apt-cache policy nodejs npm?
    – Salem
    Sep 2, 2014 at 20:49
  • nodejs: Installed: 0.10.25~dfsg2-2ubuntu1 Candidate: 0.10.25~dfsg2-2ubuntu1 Version table: *** 0.10.25~dfsg2-2ubuntu1 0 500 us.archive.ubuntu.com/ubuntu trusty/universe amd64 Packages 100 /var/lib/dpkg/status npm: Installed: 1.3.10~dfsg-1 Candidate: 1.3.10~dfsg-1 Version table: *** 1.3.10~dfsg-1 0 500 us.archive.ubuntu.com/ubuntu trusty/universe amd64 Packages 100 /var/lib/dpkg/status
    – Jonathan
    Sep 3, 2014 at 17:32
  • @Jon Please post the result of command into body of your question. in this case the result is not understandable. thanks Oct 1, 2014 at 18:42
  • @KasiyA: added. I can't imagine it'll be that helpful, though, since the versions are no different from the standard 14.04 versions.
    – Jonathan
    Oct 1, 2014 at 20:06

1 Answer 1

9
+50

The official repos are a mess...

Installing Node and npm through the official repositories has always given me trouble. I suspect that this could be due to tools depending on node, when the actual command on Ubuntu is nodejs, which is why creating a symlink should work. It worked for me in my quick test in a virtual machine, but since it didn't work for you, let's try something else...

So, install Node.JS a different way

I generally prefer to install Node on Ubuntu using NVM. This avoids the issue of the node command not being defined on Ubuntu, and it avoids the permissions mess that requires using sudo to install npm modules.

Do the following to get back to a clean slate:

Remove any global modules you've installed with npm (instructions here):

sudo npm list -g --depth=0. | awk -F ' ' '{print $2}' | awk -F '@' '{print $1}'  | sudo xargs npm remove -g

Remove symlinked node folder:

sudo rm /usr/bin/node

Uninstall the copies of nodejs and npm that you installed through Ubuntu's repositories:

sudo apt-get remove --purge nodejs npm

Clean up any other cruft:

sudo apt-get autoremove

At this point, which node, which nodejs, which npm, and which jshint should all return nothing.

Reinstall Node, skipping the official repositories

Grab the latest copy of NVM (you may need to sudo apt-get install curl first):

curl https://raw.githubusercontent.com/creationix/nvm/v0.15.0/install.sh | bash

Tell your shell to use nvm

source ~/.nvm/nvm.sh

Then install a node version

nvm install 0.12 # or whatever the latest version is

And tell nvm which version of Node you want to use

nvm use 0.12

Now you should be able to run Node with the node command, you should be able to install modules globally without sudo, and you should end up with a working copy of jshint.

If you don't want to run nvm use v0.12 every time you start a new terminal session, you can add nvm use v to your ~/.bashrc. The v isn't special, it will just match v* and find the latest version. Alternatively you could hard-code a specific version.

2
  • after following your guide, every new shell session requires me to explicitly tell shell to use node from nvm by running "nvm use v0.10". Or the session will say node is not installed and recommended me to install it using apt-get. Anyway I can make it use the node.js from nvm by default in every shell session? I thought of aliasing node to the binary in ~/nvm/v0.10.38/ , but it doesn't seem to be a good solution?
    – jimchim
    May 9, 2015 at 1:55
  • @jimchim Open up ~/.bashrc and add the line nvm use v. The v isn't special, but it should match any version (e.g. v0.12.2) so nvm should pick the latest. May 10, 2015 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .