Skip to content

Instantly share code, notes, and snippets.

@rcugut
Forked from DanHerbert/fix-homebrew-npm.md
Last active October 10, 2025 20:15
Show Gist options
  • Save rcugut/c7abd2a425bb65da3c61d8341cd4b02d to your computer and use it in GitHub Desktop.
Save rcugut/c7abd2a425bb65da3c61d8341cd4b02d to your computer and use it in GitHub Desktop.

Revisions

  1. rcugut revised this gist Jul 31, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ### DEPRECATED as of macOS 10.13 (High Sierra). See the new [GUIDE to install nvm and yarn for macOS (updated July 2019)] (https://gist.github.com/rcugut/46904124d198a9dbd430abe88ebf849b)
    ### DEPRECATED as of macOS 10.13 (High Sierra). See the new [GUIDE to install nvm and yarn for macOS (updated July 2019)](https://gist.github.com/rcugut/46904124d198a9dbd430abe88ebf849b)

    # Fixing npm On Mac OS X for Homebrew Users

  2. rcugut revised this gist Jul 31, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ### DEPRECATED, see https://gist.github.com/rcugut/46904124d198a9dbd430abe88ebf849b
    ### DEPRECATED as of macOS 10.13 (High Sierra). See the new [GUIDE to install nvm and yarn for macOS (updated July 2019)] (https://gist.github.com/rcugut/46904124d198a9dbd430abe88ebf849b)

    # Fixing npm On Mac OS X for Homebrew Users

  3. rcugut revised this gist Feb 4, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    ### DEPRECATED, see https://gist.github.com/rcugut/46904124d198a9dbd430abe88ebf849b

    # Fixing npm On Mac OS X for Homebrew Users

    Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.
  4. rcugut revised this gist Jul 13, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -136,7 +136,9 @@ npm install -g npm
    That's it. You should now be able to run the `npm` command **without `sudo`**.


    # Extra notes




    ------------
    **NEVER** run `npm` as sudo; so never do `sudo npm install ...`
  5. rcugut revised this gist Jul 13, 2017. 1 changed file with 25 additions and 0 deletions.
    25 changes: 25 additions & 0 deletions node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -107,6 +107,31 @@ prefix=/usr/local/npm_packages
    curl -L https://www.npmjs.com/install.sh | sh
    ```

    **NOTE @ July 13 2017**: the install script from above (from npmjs.com) silently fails and doesn't copy the npm package contents correctly (see comments below from @hughsw). In order to (hack)fix this you can do the following **after** running the above npm install.sh script.

    The instructions below apply to `npm 5.2.0`, but may work for earlier or later 5.x releases:

    ```bash

    # manually download and un-targz into a local dir (it will be named `package`)
    curl -L https://registry.npmjs.org/npm/-/npm-5.2.0.tgz | tar xz

    # remove the broken npm symlink (generated by the nppmjs install.sh script)
    rm -rf /usr/local/npm_packages/lib/node_modules/npm

    # move the extracted `package` in the correct place and rename to `npm`
    mv package /usr/local/npm_packages/lib/node_modules/npm

    # that should do it. The bin/npm symlinks should now work

    # make sure it works, and update to latest available npm:
    npm install -g npm

    # if you reach this step, w/o any errors => ALL OK!
    ```




    That's it. You should now be able to run the `npm` command **without `sudo`**.

  6. rcugut revised this gist Feb 8, 2017. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -35,10 +35,7 @@ brew install node --without-npm

    # install yarn (see yarnpkg.com for more info)
    brew install yarn

    ##


    # follow up with: https://yarnpkg.com/en/docs/install

    ```

  7. rcugut revised this gist Feb 8, 2017. 1 changed file with 16 additions and 3 deletions.
    19 changes: 16 additions & 3 deletions node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -20,13 +20,26 @@ Run the following commands to remove all existing global npm modules, uninstall
    # this next line erases all the existing global npm packages
    rm -rf /usr/local/lib/node_modules

    # reinstall node via brew, but without npm
    # remove previously installed node
    brew uninstall node
    brew prune # clean all broken symlinks
    brew update # always good to have the latest

    # install node 6.x (6.9.x is LTS since Oct 18 2016)
    brew install node@6 --without-npm
    # install node via brew, but without npm
    # there are 2 options:
    # - if you want to use `yarn` (yarnpkg.com), you need latest 'node'
    # - if you don't use `yarn` (yarnpkg.com), prefer LTS 'node@6'

    brew install node --without-npm


    # install yarn (see yarnpkg.com for more info)
    brew install yarn

    ##



    ```

    You should now be able to run the `node` command
  8. rcugut revised this gist Dec 5, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ brew prune # clean all broken symlinks
    brew update # always good to have the latest

    # install node 6.x (6.9.x is LTS since Oct 18 2016)
    brew install node6-lts --without-npm
    brew install node@6 --without-npm
    ```

    You should now be able to run the `node` command
  9. rcugut revised this gist Nov 16, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ brew prune # clean all broken symlinks
    brew update # always good to have the latest

    # install node 6.x (6.9.x is LTS since Oct 18 2016)
    brew install node --without-npm
    brew install node6-lts --without-npm
    ```

    You should now be able to run the `node` command
  10. rcugut revised this gist Oct 19, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ mkdir -p /usr/local/npm_packages
    # it means the permissions are wrong with your `/usr/local` folder, so fix it;
    # normally, with Homebrew, your user should own the entire `/usr/local` folder:

    sudo chown -R /usr/local
    sudo chown -R `whoami` /usr/local

    ```

  11. rcugut revised this gist Oct 19, 2016. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -22,10 +22,11 @@ rm -rf /usr/local/lib/node_modules

    # reinstall node via brew, but without npm
    brew uninstall node
    brew prune # clean all broken symlinks
    brew update # always good to have the latest

    # install node4 LTS
    brew install node4-lts --without-npm
    # install node 6.x (6.9.x is LTS since Oct 18 2016)
    brew install node --without-npm
    ```

    You should now be able to run the `node` command
  12. rcugut revised this gist May 13, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,9 @@ rm -rf /usr/local/lib/node_modules
    # reinstall node via brew, but without npm
    brew uninstall node
    brew update # always good to have the latest
    brew install node --without-npm

    # install node4 LTS
    brew install node4-lts --without-npm
    ```

    You should now be able to run the `node` command
  13. rcugut revised this gist May 11, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -95,7 +95,7 @@ curl -L https://www.npmjs.com/install.sh | sh
    ```


    That's it. You should now be able to run the `npm` command.
    That's it. You should now be able to run the `npm` command **without `sudo`**.


    # Extra notes
  14. rcugut revised this gist May 11, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ sudo chown -R /usr/local
    #### Add/append the following lines in `~/.bashrc`

    ```
    # this is where all globally installed node packages will go
    # this is the root folder where all globally installed node packages will go
    export NPM_PACKAGES="/usr/local/npm_packages"
    export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
    # add to PATH
  15. rcugut revised this gist May 11, 2016. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -45,9 +45,6 @@ mkdir -p /usr/local/npm_packages

    sudo chown -R /usr/local




    ```

    #### Add/append the following lines in `~/.bashrc`
  16. rcugut revised this gist May 11, 2016. 1 changed file with 11 additions and 4 deletions.
    15 changes: 11 additions & 4 deletions node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -36,11 +36,18 @@ You should now be able to run the `node` command
    ```bash
    # run the following commands

    sudo mkdir -p /usr/local/npm_packages
    mkdir -p /usr/local/npm_packages


    # ONLY IF THE COMMAND ABOVE FAILS >>>
    # it means the permissions are wrong with your `/usr/local` folder, so fix it;
    # normally, with Homebrew, your user should own the entire `/usr/local` folder:

    sudo chown -R /usr/local




    # normally, with Homebrew, your user should own the entire `/usr/local` folder, but this is just to be safe:
    # make sure your user is allowed to write into the folder
    sudo chown -R /usr/local/npm_packages
    ```

    #### Add/append the following lines in `~/.bashrc`
  17. rcugut revised this gist May 11, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -17,12 +17,12 @@ Run the following commands to remove all existing global npm modules, uninstall
    ```bash
    # run the following commands


    # this next line erases all the existing global npm packages
    rm -rf /usr/local/lib/node_modules

    # reinstall node via brew, but without npm
    brew uninstall node
    brew update # always good to have the latest
    brew install node --without-npm
    ```

  18. rcugut revised this gist May 11, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,9 @@ Run the following commands to remove all existing global npm modules, uninstall


    ```bash
    # run the following commands


    # this next line erases all the existing global npm packages
    rm -rf /usr/local/lib/node_modules

  19. rcugut revised this gist May 11, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -27,17 +27,17 @@ You should now be able to run the `node` command



    ### 2. Prepare the npm new home: `/ust/local/npm_packages`
    ### 2. Prepare the npm new home: `/usr/local/npm_packages`


    ```bash
    # run the following commands

    sudo mkdir -p /ust/local/npm_packages
    sudo mkdir -p /usr/local/npm_packages

    # normally, with Homebrew, your user should own the entire `/usr/local` folder, but this is just to be safe:
    # make sure your user is allowed to write into the folder
    sudo chown -R /ust/local/npm_packages
    sudo chown -R /usr/local/npm_packages
    ```

    #### Add/append the following lines in `~/.bashrc`
  20. rcugut renamed this gist May 11, 2016. 1 changed file with 80 additions and 5 deletions.
    85 changes: 80 additions & 5 deletions fix-homebrew-npm.md → node-npm-install.md
    Original file line number Diff line number Diff line change
    @@ -10,21 +10,96 @@ Before you start, make a note of any globally installed npm packages. These inst

    Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the right defaults, install npm as its own pacakge, and configure the location for global npm modules to be installed.


    ### 1. Re-install node without npm


    ```bash
    # this next line erases all the existing global npm packages
    rm -rf /usr/local/lib/node_modules

    # reinstall node via brew, but without npm
    brew uninstall node
    brew install node --without-npm
    echo prefix=~/.npm-packages >> ~/.npmrc
    curl -L https://www.npmjs.com/install.sh | sh
    ```

    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path` script, which gets run via `~/.bash_profile`.
    You should now be able to run the `node` command



    ### 2. Prepare the npm new home: `/ust/local/npm_packages`


    ```bash
    # run the following commands

    sudo mkdir -p /ust/local/npm_packages

    # normally, with Homebrew, your user should own the entire `/usr/local` folder, but this is just to be safe:
    # make sure your user is allowed to write into the folder
    sudo chown -R /ust/local/npm_packages
    ```

    #### Add/append the following lines in `~/.bashrc`

    ```
    # this is where all globally installed node packages will go
    export NPM_PACKAGES="/usr/local/npm_packages"
    export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
    # add to PATH
    export PATH="$NPM_PACKAGES/bin:$PATH"
    ```

    #### And make sure you load the `.bashrc` in your `.bash_profile`:

    - **IMPORTANT:** make sure you do not have both a `.profile` and a `.bash_profile`; if you do, copy everything from `.profile` into `.bash_profile` and then remove the `.profile`
    - Check if the following or similar line exists in your `.bash_profile`:
    ```
    [[ -s ~/.bashrc ]] && source ~/.bashrc
    ```
    - make sure `.bashrc` is executable


    ```bash
    # run the following commands

    chmod +x ~/.bashrc
    ```

    ### 3. Restart your iTerm / Terminal

    **IMPORTANT:** close all existing iTerm/Terminal sessions and re-open iTerm/Terminal before going further

    Advanced: or just reload the `.bash_profile` -- `source ~/.bash_profile`


    ### 3. Install npm from npmjs.com

    #### First, set the correct npm home in `~/.npmrc`

    Make sure `~/.npmrc` file exists, and contains a line as below:
    ```
    prefix=/usr/local/npm_packages
    ```

    #### Run the npm install script from npmjs.com
    ```bash
    export PATH="$HOME/.npm-packages/bin:$PATH"
    curl -L https://www.npmjs.com/install.sh | sh
    ```

    Now you can re-install any global npm packages you need without any problems.

    That's it. You should now be able to run the `npm` command.


    # Extra notes

    ------------
    **NEVER** run `npm` as sudo; so never do `sudo npm install ...`
    ------------



    ----------

    ## Explanation of the issue

  21. rcugut revised this gist May 9, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ curl -L https://www.npmjs.com/install.sh | sh
    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path` script, which gets run via `~/.bash_profile`.

    ```bash
    export PATH="$HOME/.node/bin:$PATH"
    export PATH="$HOME/.npm-packages/bin:$PATH"
    ```

    Now you can re-install any global npm packages you need without any problems.
  22. @DanHerbert DanHerbert revised this gist Feb 13, 2016. 1 changed file with 25 additions and 28 deletions.
    53 changes: 25 additions & 28 deletions fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,30 @@
    # Fixing npm On Mac OS X for Homebrew Users

    If you just want to fix the issue quickly, scroll down to the "solution" section below.
    Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

    ## Solution

    This solution fixes the error caused by trying to run `npm update npm -g`. Once you're finished, you also won't need to use `sudo` to install npm modules globally.

    Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

    Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the right defaults, install npm as its own pacakge, and configure the location for global npm modules to be installed.

    ```bash
    rm -rf /usr/local/lib/node_modules
    brew uninstall node
    brew install node --without-npm
    echo prefix=~/.npm-packages >> ~/.npmrc
    curl -L https://www.npmjs.com/install.sh | sh
    ```

    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path` script, which gets run via `~/.bash_profile`.

    ```bash
    export PATH="$HOME/.node/bin:$PATH"
    ```

    Now you can re-install any global npm packages you need without any problems.

    ## Explanation of the issue

    @@ -40,30 +64,3 @@ There's an [NPM bug for this exact problem](https://github.com/npm/npm/issues/37

    Also, using the Homebrew installation of `npm` will require you to use `sudo` when installing global packages. Since one of the core ideas behind Homebrew is that apps can be installed without giving them root access, this is a bad idea.

    ## Solution

    This solution fixes the error caused by trying to run `npm update npm -g`. Once you're finished, you also won't need to use `sudo` to install npm modules globally.

    Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

    Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the right defaults, install npm as its own pacakge, and configure the location for global npm modules to be installed.

    ```bash
    rm -rf /usr/local/lib/node_modules
    brew uninstall node
    brew install node --without-npm
    echo prefix=~/.node >> ~/.npmrc
    curl -L https://www.npmjs.com/install.sh | sh
    ```

    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path` script, which gets run via `~/.bash_profile`.

    ```bash
    export PATH="$HOME/.node/bin:$PATH"
    ```

    Now you can re-install any global packages with the command below, replacing the npm modules with whatever global packages you need.

    ```bash
    npm install -g http-server node-inspector forever nodemon
    ```
  23. @DanHerbert DanHerbert revised this gist Apr 18, 2015. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ If you just want to fix the issue quickly, scroll down to the "solution" section

    ## Explanation of the issue

    If you're a Mac Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew and then try to do `npm update npm -g`, you will see an error like this:
    If you're a Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew and then try to do `npm update npm -g`, you may see an error like this:

    ```
    $ npm update npm -g
    @@ -36,20 +36,24 @@ npm ERR! not ok code 0
    ```

    There's an [NPM bug open for this exact problem](https://github.com/npm/npm/issues/3794) and a long thread that is still actively being debated, but the summary is that `npm` is its own package manager and it is therefore better to have `npm` manage itself and its packages instead of letting Homebrew do it. Also, using the Homebrew version of `npm` requires `sudo` to install global packages. That's also a very bad idea.
    There's an [NPM bug for this exact problem](https://github.com/npm/npm/issues/3794). The bug has been "fixed" by Homebrew installing npm in a way that allows it to manage itself once the install is complete. However, this is error-prone and still seems to cause problems for some people. The root of the the issue is really that `npm` is its own package manager and it is therefore better to have `npm` manage itself and its packages completely on its own instead of letting Homebrew do it.

    Also, using the Homebrew installation of `npm` will require you to use `sudo` when installing global packages. Since one of the core ideas behind Homebrew is that apps can be installed without giving them root access, this is a bad idea.

    ## Solution

    This solution fixes the error caused by trying to run `npm update npm -g`. Once you're finished, you also won't need to use `sudo` to install npm modules globally.

    Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

    Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the right defaults, install npm as its own pacakge, and configure the location for global npm modules to be installed.

    ```bash
    rm -rf /usr/local/lib/node_modules
    brew uninstall node
    brew install node --without-npm
    echo prefix=~/.node >> ~/.npmrc
    curl -L https://www.npmjs.org/install.sh | sh
    curl -L https://www.npmjs.com/install.sh | sh
    ```

    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path` script, which gets run via `~/.bash_profile`.
    @@ -58,8 +62,8 @@ Node and npm should be correctly installed at this point. The final step is to a
    export PATH="$HOME/.node/bin:$PATH"
    ```

    You'll need to re-install your global node modules again. As an example, a few I use are:
    Now you can re-install any global packages with the command below, replacing the npm modules with whatever global packages you need.

    ```bash
    npm install -g grunt-cli http-server uglify-js jshint yo node-inspector forever nodemon
    npm install -g http-server node-inspector forever nodemon
    ```
  24. @DanHerbert DanHerbert revised this gist Aug 5, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ If you just want to fix the issue quickly, scroll down to the "solution" section

    ## Explanation of the issue

    If you're a Mac Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew try to do `npm update npm -g`, you will see error like this:
    If you're a Mac Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew and then try to do `npm update npm -g`, you will see an error like this:

    ```
    $ npm update npm -g
    @@ -52,7 +52,7 @@ echo prefix=~/.node >> ~/.npmrc
    curl -L https://www.npmjs.org/install.sh | sh
    ```

    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path` script, which gets called via `~/.bash_profile`. If you want to see a full example you can check out [my dotfiles repo on github](https://github.com/DanHerbert/dotfiles).
    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path` script, which gets run via `~/.bash_profile`.

    ```bash
    export PATH="$HOME/.node/bin:$PATH"
  25. @DanHerbert DanHerbert revised this gist Mar 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -61,5 +61,5 @@ export PATH="$HOME/.node/bin:$PATH"
    You'll need to re-install your global node modules again. As an example, a few I use are:

    ```bash
    npm install -g grunt-cli http-server uglify-js jshint yo nodemon
    npm install -g grunt-cli http-server uglify-js jshint yo node-inspector forever nodemon
    ```
  26. @DanHerbert DanHerbert revised this gist Mar 13, 2014. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Fixing npm On Mac OS X for Homebrew Users

    If you just want to fix the issue quickly, scroll down to the "solution" section below.

    ## Explanation of the issue

    If you're a Mac Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew try to do `npm update npm -g`, you will see error like this:
    @@ -56,8 +58,8 @@ Node and npm should be correctly installed at this point. The final step is to a
    export PATH="$HOME/.node/bin:$PATH"
    ```

    Now you should re-install any global node packages again. As an example, these are the ones I know I'll use:
    You'll need to re-install your global node modules again. As an example, a few I use are:

    ```bash
    npm install -g grunt-cli http-server uglify-js jshint bower yo nodemon
    npm install -g grunt-cli http-server uglify-js jshint yo nodemon
    ```
  27. @DanHerbert DanHerbert revised this gist Mar 13, 2014. 1 changed file with 2 additions and 7 deletions.
    9 changes: 2 additions & 7 deletions fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -40,15 +40,10 @@ There's an [NPM bug open for this exact problem](https://github.com/npm/npm/issu

    This solution fixes the error caused by trying to run `npm update npm -g`. Once you're finished, you also won't need to use `sudo` to install npm modules globally.

    First, remove globally installed node modules. This step may not be necessary, but I do it to ensure my machine is clean before continuing. **This step will be very specific to your setup. I've provided the one I ran as an example only.** All other steps are completely copy/paste verbatim after this one.

    ```bash
    sudo npm uninstall -g grunt-cli yo uglify-js nodemon jshint http-server bower
    ```

    Next, run the following commands to remove node, re-install it with the right defaults, install npm as its own module, and configure the location for global npm modules to go.
    Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the right defaults, install npm as its own pacakge, and configure the location for global npm modules to be installed.

    ```bash
    rm -rf /usr/local/lib/node_modules
    brew uninstall node
    brew install node --without-npm
    echo prefix=~/.node >> ~/.npmrc
  28. @DanHerbert DanHerbert revised this gist Mar 13, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ echo prefix=~/.node >> ~/.npmrc
    curl -L https://www.npmjs.org/install.sh | sh
    ```

    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path`, which gets called via `~/.bash_profile`. If you want to see a full example you can check out [my dotfiles repo on github](https://github.com/DanHerbert/dotfiles).
    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path` script, which gets called via `~/.bash_profile`. If you want to see a full example you can check out [my dotfiles repo on github](https://github.com/DanHerbert/dotfiles).

    ```bash
    export PATH="$HOME/.node/bin:$PATH"
  29. @DanHerbert DanHerbert revised this gist Mar 13, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ echo prefix=~/.node >> ~/.npmrc
    curl -L https://www.npmjs.org/install.sh | sh
    ```

    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable.
    Node and npm should be correctly installed at this point. The final step is to add `~/.node/bin` to your `PATH` so commands you install globally are usable. I added this line to my `~/.path`, which gets called via `~/.bash_profile`. If you want to see a full example you can check out [my dotfiles repo on github](https://github.com/DanHerbert/dotfiles).

    ```bash
    export PATH="$HOME/.node/bin:$PATH"
  30. @DanHerbert DanHerbert revised this gist Mar 13, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion fix-homebrew-npm.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    # Fixing npm On Mac OS X for Homebrew USers
    # Fixing npm On Mac OS X for Homebrew Users

    ## Explanation of the issue

    If you're a Mac Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew try to do `npm update npm -g`, you will see error like this: