Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Generators are designed to be installed globally.</strong> Otherwise, you always have to install the generator you're about to use in each project, which is unnecessarily painful. Also, you don't get to see the lovely <code>yo</code> menu which lists you all the available generators (unless of course, you install them <em>all</em> locally):</p> <p><img src="https://i.stack.imgur.com/0Y1Wp.png" alt="yo"></p> <h2>Setting up npm for global installation</h2> <p>So, how do we get npm to install packages globally? As you correctly said, you should never, ever run <code>yo</code> with sudo. There are <a href="https://gist.github.com/isaacs/579814" rel="nofollow noreferrer">lots of different solutions</a> to this problem and you can spend hours discussing their pros and cons religiously.</p> <p>I personally dislike installing my <em>user</em> packages into the <em>global</em> <code>/usr/</code> folder. <code>/usr/</code> is for software that is shared across all users on the computer. Even if it's only using the machine, there are still good reasons to respect the way the Unix file system hierarchy is designed. For example if you decide at one point to wipe your whole node installation.</p> <p>My preferred way of enabling <code>npm</code> to install packages globally <em>without breaking out of <code>$HOME</code></em> is <a href="https://gist.github.com/isaacs/579814#file-yet-another-option-sh" rel="nofollow noreferrer">to set a local node prefix</a>. This is as easy as running</p> <pre><code>echo 'prefix = ~/.node' &gt;&gt; ~/.npmrc </code></pre> <p>in your local shell. After that, you want to adjust your $PATH, to point to the new installation destination for global node executables by adjusting your favorite shell's config. E.g. by adding</p> <pre><code>export PATH="$PATH:$HOME/.node/bin" </code></pre> <p>to your <code>~/.bashrc</code>. After that, you can happily run <code>npm install -g generator-angular</code> without sudo, without running into permission conflicts and if something is completely broken and you want to start from scratch, all you need to do is remove your <code>~/.node</code> directory.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload