coffeescript install

2019-06-16 05:52发布

问题:

I can't install CoffeeScript on my Macbook. The same commands works just fine on my iMac.

$ surganov:~ surganov$ sudo npm install coffee-script -g
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
coffee-script@1.3.3 /usr/local/share/npm/lib/node_modules/coffee-script

$ surganov:~ surganov$ coffee
-bash: coffee: command not found

回答1:

If you want to access coffescript binary globally, you need to install it so:

npm install -g coffee-script

And then add the installation directory to your PATH. Good way to automate this is to use nvm.



回答2:

I had the same problem. When install with '-g', npm install to /usr/local/share/npm so you can't use, eg 'coffee' command. You can check where npm install node_modules with:

npm prefix -g

If it's not /usr/local then you can use npm config edit to edit prefix. It'll create a .npmrc file in your root (if it's not there). Otherwise, open the file with text editor and change the prefix. More info here: npm config



回答3:

  • Locate your coffeescript bin directory (by typing locate coffee)
  • Edit your ~/.profile file and add: export PATH=/usr/local/lib/node_modules/coffee-script/bin::$PATH (or whereever your coffee-script/bin is located)
  • Save the profile file
  • type source ~./profile (only this time) to load the new path
  • now you have the coffee command