69

I used node.js to install karma. My first try failed when running the following command on Terminal:

npm install -g karma

That failed so I decided to use:

sudo npm install -g karma

After entering my password it seemed to install correctly. I am pasting part of the output of the install, maybe it will mean something to someone and it will be relevant to my question. After all the npm http messages this is what I see:

> ws@0.4.27 install /usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
  SOLINK_MODULE(target) Release/bufferutil.node
  SOLINK_MODULE(target) Release/bufferutil.node: Finished
  CXX(target) Release/obj.target/validation/src/validation.o
  SOLINK_MODULE(target) Release/validation.node
  SOLINK_MODULE(target) Release/validation.node: Finished
/usr/local/share/npm/bin/karma -> /usr/local/share/npm/lib/node_modules/karma/bin/karma
karma@0.8.6 /usr/local/share/npm/lib/node_modules/karma
├── pause@0.0.1
├── dateformat@1.0.2-1.2.3
├── xmlbuilder@0.4.2
├── colors@0.6.0-1
├── chokidar@0.6.2
├── growly@1.1.1
├── mime@1.2.9
├── q@0.9.6
├── rimraf@2.1.4 (graceful-fs@1.2.3)
├── coffee-script@1.6.3
├── minimatch@0.2.12 (sigmund@1.0.0, lru-cache@2.3.0)
├── optimist@0.3.5 (wordwrap@0.0.2)
├── glob@3.1.21 (inherits@1.0.0, graceful-fs@1.2.3)
├── LiveScript@1.0.1 (prelude-ls@1.0.1)
├── log4js@0.6.6 (dequeue@1.0.3, semver@1.1.4, async@0.1.15, readable-stream@1.0.2)
├── lodash@1.1.1
├── http-proxy@0.10.3 (pkginfo@0.2.3, utile@0.1.7)
├── istanbul@0.1.22 (abbrev@1.0.4, which@1.0.5, fileset@0.1.5, nopt@2.0.0, wordwrap@0.0.2, async@0.1.22, mkdirp@0.3.5, esprima@0.9.9, escodegen@0.0.24, handlebars@1.0.12)
└── socket.io@0.9.16 (base64id@0.1.0, policyfile@0.0.4, redis@0.7.3, socket.io-client@0.9.16)

Then when I try to run the following command to create a karma config file with this command:

karma init karma.config.js

this is the message that gets returned:

-bash: karma: command not found

I have tried the same command with sudo before it but I get the same result.

Does anyone have any idea as to what is going on? Any help is appreciated.

*Update! I decided to check a file named: builderror.log located in: /usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws

This is what it shows:

gyp WARN EACCES user "root" does not have permission to access the dev dir "/Users/eperez/.node-gyp/0.10.5"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/.node-gyp"
gyp http GET http://nodejs.org/dist/v0.10.5/node-v0.10.5.tar.gz
gyp http 200 http://nodejs.org/dist/v0.10.5/node-v0.10.5.tar.gz
iChido
  • 2,252
  • 6
  • 21
  • 27
  • 1
    it's apparently not in your path, confirm with `which karma`. i've experienced npm installing stuff to a not-in-path-by-default location, I think on Arch. i don't remember where it went though sorry :( ps you can do `cd /; find|grep karma` to get all filenames on system with karma in filename or path – Plato Jul 17 '13 at 15:49
  • I ran the command and this is what I got. Not sure what it means though: `usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]` – iChido Jul 17 '13 at 19:27
  • OK sorry your `find` program behaves differently than mine. Anyway you will need to find where npm installed stuff and make sure that folder is added to your path for your terminal sessions. FWIW on my Linux Mint install, `npm -g` puts stuff in `/usr/local/bin` – Plato Jul 17 '13 at 20:45
  • I have the same issue. None of the suggestions/answers helped. – Doug Mar 19 '14 at 00:50
  • 114
    The command line interface is in a separate package. To install this use: `npm install -g karma-cli` – mayankcpdixit Mar 26 '14 at 11:56

9 Answers9

250

@mayankcpdixit gave the answer up there in a response to the OP's original question, but I'll put it here again in case anyone misses it.

You do not need to uninstall everything, and if I had to manually add a new path link for every npm package I try to install I'd probably shoot myself.

npm install -g karma-cli

Boom. Now you have karma command lines installed. Just like Grunt.


Edit: Please don't forget to upvote @mayankcpdixit as well, he commented directly on the original post, but didn't actually "answer" the question.

Community
  • 1
  • 1
Kirkland
  • 3,207
  • 1
  • 14
  • 17
  • 9
    Remember that `-g` requires sudo privileges so it should be `sudo npm install -g karma-cli` ;) – sol4me Jan 09 '15 at 11:58
37

In your ~/.bash_profile (or similar) amend your PATH to include npm-installed binaries:

export PATH="$PATH:/usr/local/share/npm/bin"

I had this very same issue, and found this solution to be less time-consuming and impactful than completely re-installing node.

EDIT this has also worked for others in bash_profile

export PATH="$PATH:/usr/local/lib/node_modules/karma/bin" 
Marty Cortez
  • 2,275
  • 1
  • 15
  • 22
  • 9
    I had to use: ```export PATH="$PATH:/usr/local/lib/node_modules/karma/bin"``` in ```~/.bash_profile```. – Jason Shah Dec 27 '13 at 16:34
  • 1
    Can't decide whether to make sure Karma is in my path or completely reinstall Node... +1 – Matt Jensen Apr 09 '14 at 06:50
  • Couldn't get this to work. This is with a global installation or karma, correct? – grant May 09 '14 at 13:36
  • @grant sorry you couldn't get it to work (and for this late response). Yes, it was with a global installation of karma. – Marty Cortez Jun 10 '14 at 22:32
  • @MartinCortez no problem. I found out that my problem had to do with the node prefix which wasn't set to /usr/local as it should have been http://stackoverflow.com/questions/14803978/npm-global-path-prefix – grant Jun 11 '14 at 15:35
  • 1
    if you are using oh my zsh make the edits in ~/.zshrc – DamongoCoder Mar 02 '15 at 21:18
14

It is recommended to install karma with its Command-Line-Interface (karma-cli) which will take care of fetching the appropriate karma. You can also install a different local version specific to each project you're working on and karma-cli will pick the appropriate one.

From the karma installation page:

Typing ./node_modules/karma/bin/karma start sucks so you might find it useful to install karma-cli globally:

npm install -g karma-cli

Now, check that karma was installed by typing:

karma start

You can also check that karma was installed by going to this directory:

cd /usr/local/lib/node_modules/karma

Good luck!

Lior Elrom
  • 15,194
  • 15
  • 68
  • 84
2

Don't need to completely uninstall node.js

Just

sudo rm -rf /usr/local/lib/node_modules/npm/

Then
install node.js

Then
reinstall karma

This worked for me.

vusan
  • 4,634
  • 4
  • 36
  • 76
2

I had to add export PATH="$PATH":/usr/local/lib/node_modules/npm/node_modules/karma/bin after installing karma with sudo npm install karma.

hope this helps.

1

Just go to test.sh:

Find: $BASE_DIR/../node_modules/karma/bin/karma start $BASE_DIR/../config/karma.conf.js $*

Replace with: /usr/local/bin/karma start $BASE_DIR/../config/karma.conf.js $*

Or: karma start $BASE_DIR/../config/karma.conf.js $*

1

I was also facing the same issue. It looks like karma for command line is a separate package which can be installed by

npm install -g karma-cli

skjoshi
  • 2,165
  • 2
  • 25
  • 32
  • 1
    For anyone's info: I also had to add karma-cli to my package.json so it would run on Circle CI. – Rimian Oct 16 '14 at 04:55
0

When upgrading from Karma 0.10 to 0.12 the link to the karma executable is removed.

You can get it back with

cd node_modules/.bin
ln -s ../karma/bin/karma karma
OnnoH
  • 23
  • 4
-21

Try re-installing node.js. There are lots of ways to install it, but I recommend downloading from nodejs.org

If that doesn't work, you may try to re-install karma.

dob
  • 138
  • 1
  • 6
  • I had originally installed node through homebrew. I unlinked node then downloaded node.js from the website. Installed the pkg file and everything seems to be working fine now. Thank you! – iChido Jul 17 '13 at 20:56