Install Git, Node.js and Grunt in Windows 7 office environment (no admin rights are required)

This post contains a solution to install Git, Node.js and grunt in Windows 7 office environment, but as for Grunt, it can be useful for Mac or Linux users, too. As regards installing Node.js, it is only EXPERIMENTAL, and the main aim was to do exercises and not serious work with Grunt.

I will focus on Windows 7, but in other environments the necessary steps to use Grunt are the same, such as

  • you need to install the Node.js,
  • you use node package manager for Grunt,

so I hope you may find useful the Grunt section of this post even if you work on other system.

Working on a PC when you don't have admin rights is horrible, but you can more or less manage it for example with the help of portable softwares. So what to do, if some application doesn't have official portable version? Maybe you first try to find other portable solution on the web, but sometimes they don't work in your environment. If your coveted software is open source, you can try to build it, but without admin rights it is quite impossible. Finally you can start to experiment.

Install Git on Windows

As for Git, it is pretty simple to install it in Windows environment. Its installer didn't require admin rights. It provides a BASH emulation used to run Git from the command line (git bash), and also provides a git GUI. You can download it from here: http://git-scm.com/download/win. With the bash emulator you can use Git in a linux like environment.

Git bash is not necessary for Node.js, but one of my aims was to simulate the work flow I hammered out on my Mac. So you don't need to use Git bash for Node.js and Grunt, but if you use git on Linux or OS X, it will be quite a familiar tool for you.

Install Node.js and the node package manager (npm) on Windows

Get node.js and npm

After a lot of trial and error I ended up with http://nodejs.org/dist/. You can always find here the latest release of node binary, and the node package manager library, too. They work fine with Git bash. I downloaded the following:

Create a folder for node, and copy to folder node.exe

I created my node directory in my home directory, but you can create it anywhere you want.

Extract the npm package and
  • in case of your npm package is zip, copy the unzipped files to your node folder
  • in case of your npm package is tar, create a sub folder in the node folder called "node_modules", and copy here the untarred files.
Copy npm file

Copy to your node folder the npm file from node-modules/npm/bin folder (not the windows batch file but the other npm file; the windows batch file already exists in the node folder, but in Git bash you won't need it).

Now you have node and npm. Maybe want to create the appropriate path for npm. I ran Git bash, and created a .bashrc file in my home directory with this content:

export PATH=$PATH:~/node/

After log out and login, you can run npm from anywhere.

Installing Grunt and test jshint plugin

There is a nice tutorial on gruntjs.com about how to install Grunt, and some basics about how to use it: install grunt plugin.

Install grunt-cli

First, you have to install grunt-cli globally:

nmp install -g grunt-cli

Maybe you want to create a path to the grunt file. You can figure out the exact path after you installed grunt-cli. At the end of the prompt message you can see something like this:

c:\Users\user\node\grunt -> c:\Users\user\node\node_modules\grunt-cli\bin\grunt
grunt-cli@0.1.13 c:\Users\user\node\node_modules\grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.4)
└── findup-sync@0.1.3 (lodash@2.4.1, glob@3.2.9)

It says that grunt file is located in c:\Users\user\node\node_modules\grunt-cli\bin\
I created an other path in my .bashrc file in order to have the possibility to get grunt from anywhere:

export PATH=$PATH:~/node/node_modules/grunt-cli/bin/

Set up your grunt environment
  • In your project folder, create a package.json file (you can create a basic package.json file with npm init)

  • In your project folder install grunt locally, and add grunt to your devDependencies:

npm install grunt --save-dev
  • install jshint plugin and add grunt to your devDependencies
npm grunt-contrib-jshint --save-dev
  • I created an src directory, and put some dummy code (grunt-play.js) here to check jshint:
function Hello() {
    console.log("Hello");
}
Hello();
  • Create Gruntfile.js in your project directory. Here is a simple example on the base of the getting started section of gruntjs.com:
module.exports = function(grunt) {
  // Project configuration.
  grunt.initConfig({
    jshint: {
      files: ['gruntfile.js', 'src/**/*.js'],
    }
  });

  // Load the plugin that provides the "jshint task.
  grunt.loadNpmTasks('grunt-contrib-jshint');

  // Default task(s).
  grunt.registerTask('default', ['jshint']);
};
  • Now we can type grunt, and test our code with jshint:
user@WKD012485 project folder $ grunt

Running "jshint:build" (jshint) task
>> 1 file lint free.

Done, without errors.


comments powered by Disqus