37

I went ahead and installed and tested node.js and then I installed LESS CSS via NPM but when I type in the command

lessc styles.less

or

lessc styles.less > styles.css

It tells me -bash: lessc: command not found

I'm in MAC Lion Terminal program

EDIT:

After installing Node you need to run this command

ln -s ~/.npm/less/1.2.1/package/bin/lessc (path to directory you want)

Then you will be able to run less on any of the less files in that directory.

It works but it's not compiling the imports into one CSS file. It just leaves the imports in the file as is. I was hoping I could combine all of the CSS inside the files that I'm importing together.

elitalon
  • 9,191
  • 10
  • 50
  • 86
Chris
  • 823
  • 2
  • 7
  • 16
  • Did you restart your terminal's session/reloaded your paths? – chelmertz Jan 30 '12 at 19:06
  • Whoops! No I didn't. I changed the question because I was able to figure it out. I just needed to install the less in the directories I wanted to use them in. I used this command ===> ln -s ~/.npm/less/1.2.1/package/bin/lessc (path to directory) – Chris Jan 30 '12 at 19:43
  • This is a bug with `npm/less` see https://github.com/less/less.js/issues/1464 – sorin Aug 03 '13 at 07:23
  • Note that this problem can occur if you installed node through homebrew on Mac a while ago, new brew node installs should be ok - it's not a less bug, but it was a homebrew bug: https://github.com/Homebrew/homebrew/issues/21627 – benz001 Apr 19 '14 at 06:46

2 Answers2

34

When you install LESS via npm use the -g option to install it globally.

npm install -g less

TJ VanToll
  • 12,584
  • 4
  • 43
  • 45
  • Or if you don't want to pollute the system, install without `-g` then simply invoke `./node_modules/less/bin/lessc` from the directory you were under when doing `npm install less` – JSmyth Mar 05 '15 at 07:52
16

When installing packages with npm you have two options:

  1. Install them globally: npm install -g <package>
  2. Install locally in your home directory under ~/.npm: npm install <package>

If you choose option 1 your system should be able to locate the binary lessc. If you choose option 2 you should add ~/.npm/less/path_to_bin_directory to your path:

export PATH=~/.npm/less/path_to_bin_directory:$PATH

or better, if a ~/node_modules directory has been created as a result of installation:

export PATH=~/node_modules/less/path_to_bin_directory:$PATH
elitalon
  • 9,191
  • 10
  • 50
  • 86