I recently set up node.js on my system and installed the LESS CSS preprocessor through NPM. However, when I try to run the compiler commands in my terminal, I get an error message.
When I execute:
lessc main.less
or try to output to a file:
lessc main.less > output.css
I get the error: -bash: lessc: command not found
I’m working on macOS using the built-in Terminal application. I thought the lessc command would be available globally after the NPM installation, but it seems like the binary isn’t in my PATH.
Has anyone encountered this issue before? What’s the proper way to make the LESS compiler accessible from anywhere in the terminal? I need to be able to compile my LESS files to CSS for my project.
When you encounter the ‘-bash: lessc: command not found’ error after installing LESS, it often means that you installed it locally instead of globally. To resolve this, you should run the command npm install -g less, which installs LESS globally and makes the lessc command accessible anywhere in your terminal. If permission issues arise on macOS, consider prefacing the command with sudo, but it’s better to configure npm for global installs without it. After installation, check it’s working by executing lessc --version.
Had the exact same problem when I first started using LESS on my Mac. The issue is typically that npm’s global bin directory isn’t added to your PATH environment variable. Even after running the global install command, you might still face this issue. Try running npm config get prefix to see where npm installs global packages, then check if that path plus /bin is in your PATH by running echo $PATH. If it’s missing, you’ll need to add it to your shell profile file like .bash_profile or .zshrc depending on your shell. Alternatively, you can run npx lessc main.less which will work even with a local installation and doesn’t require messing with PATH variables.