Brew Node NPM Grunt tips - mhulse/mhulse.github.io GitHub Wiki

Get Homebrew version:

$ brew --version
0.9.4

Dependencies:

  • Terminal must be set to /usr/bin/login rather than /bin/bash/ or another login shell
  • run
$ brew install git

to enable GitHub updates to brew

  • Mac OS 10.6.* must have Xcode 3.2.6* to properly run git updates *requires developer login credentials (free-level access ok)

Regularly run:

$ brew update
# ... or:
$ brew update && brew cleanup
# You can run this less often:
$ brew upgrade

Fetch the newest version of Homebrew from GitHub using git.


Troubleshoot:

$ brew doctor

Check your system for potential problems. Doctor exits with a non-zero status if any problems are found.

Super useful:

$ brew info [package name]

For more info on brew, use:

$ man brew

Tip: Use u and d keys to travel up/down the man page; use :q to exit.


If you can't remember some commands you've used in the past, you can always grep your history:

$ history | grep npm

Create a package.json file using:

$ npm init

This will ask you a bunch of questions, and then write a package.json for you.

… and follow the on-screen instructions.

For more on npm:

$ npm --help

To see more info for a particular command, run:

$ npm help init

… where init can be any one of the available commands.

Checking versions of installed packages:

# For locally installed packages:
$ npm list
# For globally installed packages:
$ npm list -g
# Locally installed, without their dependencies:
$ npm list --depth=0
# Globally installed, without their dependencies:
$ npm list --depth=0 -g
# View latest latest version available on npmjs.org:
$ npm view <package-name> version

Upgrade an npm package:

$ npm update # Updates all local packages.
$ npm update item # Where "item" is a package name.
$ npm update -g # Updates all "global" npm packages.
$ npm update item -g # Where "item" is a "global" package name.

Update npm (Oct. 2014):

$ npm install -g npm@latest

Start using Grunt 4.0 now!

UPDATE Grunt 0.4.0 has been released!!!! Read more here.

First, uninstall any previous global installs of grunt:

$ sudo npm uninstall -g grunt

Then install the CLI:

$ sudo npm install -g grunt-cli

Now read these docs:

https://github.com/gruntjs/grunt/wiki/Getting-started

http://gruntjs.com/getting-started

Tip: The master branch is the latest version (0.4). The older version of grunt (0.3) can be found here:

https://github.com/gruntjs/grunt/tree/0.3-stable

I point this out because it's kinda confusing at this time due to the current transition from 0.3 to 0.4.

Source code and more docs can be found here:

https://github.com/gruntjs/grunt


If you have a package.json setup and have yet to install anything locally, cd to the project directory and run:

$ npm install

After install, brew doctor may likely brew report that

$ brew doctor
Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. ... [snip] ... 

echo $PATH will show you the order that the bash shell (the OS X default Unix shell) searches for things. Doing that, you'll see what brew is talking about.

One way is to edit your ~/.profile file.

Another way to re-arrange the order is to update /Volumes/XXXXX/private/etc/paths

Was:

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

Changed to:

/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin

See: Homebrew wants me to amend my PATH. No clue how

Note: A quick way to get to the /private/etc/paths file is to go to the Finder, type Shift + Command + G and enter-in /private/etc/. From there, find the paths file, open and edit it.

Note: You may need to restart the machine for brew doctor to note that the changes have been made.


I ended up un-installing Node's .pkg install and installed it using Homebrew instead.

I ran into some issues along the way. Here's my bash history for future reference:

  483  brew install node
  484  rm -rf /usr/local/lib/node_modules/npm
  485  brew link node
  486  rm -rf /usr/local/share/man/man1/node.1
  487  brew link
  488  brew link node
  489  brew link --overwrite node
  490  sudo brew link --overwrite node
  491  brew link --overwrite node
  492  npm link node
  493  brew link node
  494  rm -rf /usr/local/lib/dtrace/node.d
  495  sudo chown -R whoami /usr/local/lib/dtrace/node.d
  496  brew link -n node
  497  brew link node
  498  rm /usr/local/lib/dtrace/node.d
  499  brew link node
  500  brew link --overwrite node
  501  brew install node
  502  brew link node
  503  brew link --overwrite node
  504  rm -rf /usr/local/lib/node_modules/npm
  505  brew link node
  506  brew link -n node
  507  rm -R /usr/local/Cellar/node/0.8.10/lib/node_modules/npm
  508  rm -rf /usr/local/lib/node_modules/npm
  509  brew link node
  510  rm -f /usr/local/lib/dtrace/node.d
  511  sudo rm -f /usr/local/lib/dtrace/node.d
  512  brew link node
  513  rm -rf /usr/local/lib/node_modules/npm
  514  brew link node
  515  sudo chown 'whoami' /usr/local/lib/dtrace
  516  sudo chown -R whoami/usr/local/lib/dtrace
  517  sudo chown -R whoami /usr/local/lib/dtrace
  518  brew link node
  519  chmod +w /usr/local/lib/dtrace
  520  brew link node
  521  cd /usr/local/lib/
  522  ls -la
  523  sudo chown -R mhulse /usr/local/lib/dtrace
  524  ls -la
  525  sudo chown -R mhulse:admin /usr/local/lib/dtrace
  526  ls -la
  527  brew link node

See:

How things went on my work computer:

I used this script:

nicerobot / uninstall-node.sh

Do: $ chmod u+x uninstall-node.sh and then $ ./uninstall-node.sh.

When running $ brew install node, I got this message:

Warning: Could not link node. Unlinking...
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link node'

Using $ brew link node I got:

Error: Could not symlink file: /usr/local/Cellar/node/0.8.20/include/node/v8stdint.h
/usr/local/include/node is not writable. You should change its permissions.

So based on info found here, I removed:

$ sudo rm -rf ./node

Next, $ brew link node gave me:

Error: Could not symlink file: /usr/local/Cellar/node/0.8.20/lib/dtrace/node.d
/usr/local/lib/dtrace is not writable. You should change its permissions.

This time, using the Finder, I navigated to /usr/local/lib/ and moved the "dtrace" folder to the trash.

Now:

$ brew link node

... gave me:

Linking /usr/local/Cellar/node/0.8.20... 8 symlinks created

WOOT!

Lastly, I added /usr/local/share/npm/bin to the top of my paths file (/Volumes/XXXXX/private/etc/paths):

/usr/local/share/npm/bin
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin

... as $ brew install node had said earlier:

Homebrew installed npm. We recommend prepending the following path to your PATH environment variable to have npm-installed binaries picked up: /usr/local/share/npm/bin

Note: You'll probably want to run $ brew doctor and $ brew update now.

I restarted my computer for completeness' sake. :)


How to update node.js, npm and all other dependencies?

$ brew upgrade node

Troubleshooting: If you had previously installed a development version of Grunt 0.4 or any grunt-contrib plugins, be sure to flush your npm cache with npm cache clean first to ensure that you are pulling the final version of Grunt and grunt-contrib plugins.

Upgrading from 0.3 to 0.4


⚠️ **GitHub.com Fallback** ⚠️