2
votes

I'm having some difficulty installing Node and Coffeescript. I have installed node using homebrew and then I have successfully installed NPM. I have tried to install Coffeescript from NPM and it appears to have worked but then I cannot run coffee

localserver:Documents x$ sudo npm -g install coffee-script
Password:
npm http GET https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/coffee-script
/usr/local/share/npm/bin/coffee -> /usr/local/share/npm/lib/node_modules/coffee-script/bin/coffee
/usr/local/share/npm/bin/cake -> /usr/local/share/npm/lib/node_modules/coffee-script/bin/cake
[email protected] /usr/local/share/npm/lib/node_modules/coffee-script
localserver:Documents x$ coffee
-bash: coffee: command not found
localserver:Documents x$ 

Is there some path environment variable that I need to set for this? Even if I navigate to /usr/local/share/npm/lib/node_modules/coffee-script/bin/coffee I cannot run it from here.

2
Did you try running the following command: /usr/local/share/npm/lib/node_modules/coffee-script/bin/coffee? - Florian Margaine
That actually works. I'm just getting my head round unix - why would it work entering the full path but not being in that place and running it from here? - Mr Wilde
Because if you just type coffee, it will look for the coffee script in your PATH settings. If you just type the name of the script (with its path), it will execute it. If you're in the path of the script, you need to type ./coffee (. being current directory). - Florian Margaine
never ever use sudo for node package manager as recommended in the documentation: howtonode.org/introduction-to-npm. if you already used sudo, you should reorganize your permissions of installed global modules that sudo isnt nessesary - itinance

2 Answers

6
votes

Looks like npm doesn't add coffee's directory to the PATH. You can fix it with the following:

export PATH=/usr/local/share/npm/lib/node_modules/coffee-script/bin/:$PATH

I'm quite sure there must be a better way though. But I don't know enough OSX to answer.

If you want this change to be permanent, add the line to your ~/.profile file.

6
votes

On Mac OS X, .bashrc is the best place to specify your $PATH (bashrc vs bash_profile).

You want to add a path that will work for all (globally installed) Node modules, which would be /usr/local/share/npm/bin. To do that, you can type the following into your shell (where ^D means pressing Control-D to end the input).

cat >> ~/.bashrc

export PATH="/usr/local/share/npm/bin:${PATH}"
^D