Installing Grunt, osx, nvm, zsh - node.js

Installing Grunt
I have osx yosemite, zsh, nvm. The version of node I am using is v0.10.33.
I installed node in a way I do not need to use sudo (node and npm reside in my home folder)
here where I export the global dependencies in my zshrc
export NODE_PATH=/Users/nickname/.node/lib/node_modules/:/Users/nickname/.node/lib/node_modules
Just for information, I am trying to install Ghost (the blogging plataform).
I cloned like this to get the stable version
git clone -b stable https://github.com/TryGhost/Ghost.git ghost
and then
cd ghost/
git submodule update --init
npm install -g grunt-cli
npm install
grunt init
The error I am getting is that is not able to find grunt
Ghost git:(stable) grunt init
zsh: command not found: grunt

You're not supposed to install grunt globally, only grunt-cli. The grunt package should be installed in your project directory using something like:
~$ npm install grunt --save-dev
That will add a line to your project's package.json file, then you configure a "Gruntfile.js" for your project with tasks that are run from the command line with:
~$ grunt taskname

Related

Gulp: /usr/local/bin/gulp: No such file or directory

Whenever I run gulp, I get the following error:
/usr/local/bin/gulp: No such file or directory
I've followed the answers to several related questions on SO, but none have solved my issue. I've been using gulp without issue for months, but managed to screw it up somehow.
I've removed gulp and gulp-cli (using npm) both locally and globally.
After running the following:
npm install -g gulp-cli
npm install --save-dev gulp
Any command using gulp, even gulp -v returns the error mentioned above. There are no errors during the installation.
I've confirmed there is nothing at /usr/local/bin/gulp, but shouldn't reinstalling things recreate whatever files are supposed to be there?
Any help is appreciated.
EDIT:
Installing gulp globally npm install -g gulp doesn't fix anything.
Do you want to install gulp locally or globally?
Locally
npm install --save-dev gulp gulp-cli should do the trick. You can then run it using:
./node_modules/.bin/gulp
npm run gulp if you add gulp to the scripts section of package.json.
Globally
Most likely you have a $PATH issue.
Did you check where your global libraries are installed by NPM?
npm list -g
Does installing any other global library work, or is it specific to Gulp?
-- Edit --
If you are using NVM, you should add the NVM setup to your rcfile (that is, ~/.bashrc, ~/.zshrc, ~/.profile or similar). You can do so by appending these lines to your rcfile.
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh
This will load NVM and update your PATH so that your shell is able to find gulp (or any other globally-installed program by npm or yarn).
Try npx gulp so that npm using the gulp version that is installed in your dependencies.

Where to install gulp?

I'm trying to leverage from Elixer so I started to get up and running. I've installed Node and Npm. Later I also installed Gulp using sudo npm install gulp -g. But this installed Gulp in my project directory, resulting in a massive file transfer from my local host to the webserver. Is it necessary to install Gulp inside the project directory? Or is there a better way to install it somewhere else and use it for any project needed?
Sorry if this is a total beginners question but I can't seem to find an answer online. Thanks.
There is only few steps to start use it.
Install globally $ npm install --global gulp
Install directly to your project root dir $ npm install --save-dev gulp
Create gulpfile.js in root dir
Then in your new gulpfile do the follow:
var gulp = require('gulp');
gulp.task('default', function() {
// place code for your default task here
});
and after that just type gulp command in terminal to execute default task
here is documentation to help you started with gulp docs and here you can find packages to use it npmjs.com
Tip: if you on OSX use sudo to install npm/jspm/gulp etc
sudo npm install gulp -g shouldn't be installing gulp in your project directory. However, Gulp does always need to be installed locally in the project folder in order for it to work. Otherwise, you will get an error when trying to run Gulp. The -g global installion of Gulp is only needed for linking the shell to the binary $ gulp; it will dispatch to the local gulp program as soon as it is called.
Gulp, bower, ... are dependencies.
The command npm install ... will download the module to the directory named node_modules. They need to be (litterally) a part of your project. Think of it as a pure JS library (as it actually is).

Homebrew Install Node Location

Kinda 2 questions related to each other here.
When doing a brew install node, should I first navigate to the root of whatever folder I'm going to hold all my future web projects/apps then run it? Or does it not matter where I run the install initially for Node? Because I notice it creates a node_modules folder in /local/lib/node_modules
I assume it doesn't matter, and when you start installing node packages using npm install [package] it'll create a separate node_modules folder under the context you're in so lets say /www/MyApplication run npm install and it'll create /www/MyApplication/node_modules....and that the one under /local/lib/node_modules just serves as the one for npm itself because it needs its own root node_modules folder which is how npm runs?
Correct, it makes no difference where you run brew install node, it will install into your Homebrew folder.
When you use npm to install a Node module, it will install into the current directory, unless you use the -g global flag. Normally you will install modules that are project dependencies into your project folder, and global modules are for global utilities.
For example, to use Grunt you would install the grunt-cli package globally for the command-line utility.
npm install -g grunt-cli
And for each project that uses Grunt you will install a version of the grunt module for use with the project.
npm install grunt

Grunt installation in mac os

I want to create angular js app using bootstrap, for that I installed node.js pkg file in my mac.
Afterwards I installed yeoman ($sudo npm install --global yo). Documentation says if we install yo then we get grunt and bower automatically installed. In my case grunt and bower are not being installed.
So I decided to install it externally. I used following commands:
$sudo npm install -g bower => it works perfectly and giving me all files and packages.
$ sudo npm install -g grunt => it works perfectly but not giving me all files and packages
grunt are installed on path of usr/local/lib/node_modules/grunt
grunt folder contains files
constributing.md
licenses-mit
readme
aaveyor.yml
internal-tasks
lib
node_modules
package.json
Which files I am missing?
If I run command $ grunt --version then I got following error
-bash: /grunt: No such file or directory
How to resolve this?
You have to run:
$ npm install -g grunt-cli
The global binary command-line tool is grunt-cli, not grunt. It's a little bit confusing in the beginning, as grunt-cli provides a global binary which is callable by grunt.
So, in the end:
Install grunt locally in your application.
Install grunt-cli globally.
Then, you can run grunt from anywhere as expected :-)

"Fatal error: Unable to find local grunt." when running "grunt" command

I uninstalled grunt with following command.
npm uninstall -g grunt
Then I again installed grunt with following command.
npm install -g grunt-cli
Visit following link:
https://npmjs.org/package/grunt-html
I want to use the above grunt plugin
But when I run the grunt command it gives me following error:
D:\nodeJS\node_modules\grunt-html>grunt
grunt-cli: The grunt command line interface. (v0.1.6)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
All is explained quite nicely on gruntjs.com.
Note that installing grunt-cli does not install the grunt task runner!
The job of the grunt CLI is simple: run the version of grunt which has
been installed next to a Gruntfile. This allows multiple versions of
grunt to be installed on the same machine simultaneously.
So in your project folder, you will need to install (preferably) the latest grunt version:
npm install grunt --save-dev
Option --save-dev will add grunt as a dev-dependency to your package.json. This makes it easy to reinstall dependencies.
You have to install grunt in your project folder
create your package.json
$ npm init
install grunt for this project, this will be installed under node_modules/. --save-dev will add this module to devDependency in your package.json
$ npm install grunt --save-dev
then create gruntfile.js and run
$ grunt
I think you have to add grunt to your package.json file. See this link.
I had this issue on my Windows grunt because I installed the 32 bit version of Node on a 64 bit Windows OS. When I installed the 64bit version specifically, it started working.
I had the same issue today on windows 32 bit,with node 0.10.25, and grunt 0.4.5.
I followed dongho's answer, with just few extra steps.
here are the steps I used to solve the error:
1) create your package.json
$ npm init
2) install grunt for this project, this will be installed under node_modules/. --save-dev will add this module to devDependency in your package.json
$ npm install grunt --save-dev
3) then create gruntfile.js , with a sample code like this:
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
globals: {
jQuery: true
}
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['jshint']);
};
here, src/**/*.js and test/**/*.js should be the paths to actual JS files you are using in your project
4) run npm install grunt-contrib-jshint --save-dev
5) run npm install grunt-contrib-watch --save-dev
6) run $ grunt
Note: when you require common package like concat, uglify etc, you need to add those modules via npm install, just the way we installed jshint and watch in step 4 & 5
if you are a exists project, maybe should execute npm install.
guntjs getting started step 2.
This solved the issue for me. I mistakenly installed grunt using:
sudo npm install -g grunt --save-dev
and then ran the following command in the project folder:
npm install
This resulted in the error seen by the author of the question.
I then uninstalled grunt using:
sudo npm uninstall -g grunt
Deleted the node_modules folder. And reinstalled grunt using:
npm install grunt --save-dev
and running the following in the project folder:
npm install
For some odd reason when you global install grunt using -g and then uninstall it, the node_modules folder holds on to something that prevents grunt from being installed locally to the project folder.

Resources