<h1 id="npm-update1">npm-update(1)</h1>

<h2 id="update-a-package">Update a package</h2>

<h3 id="synopsis">Synopsis</h3>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>npm update <span class="o">[</span><span class="nt">-g</span><span class="o">]</span> <span class="o">[</span>&lt;pkg&gt;...]

aliases: up, upgrade
</code></pre></div></div>

<h3 id="description">Description</h3>

<p>This command will update all the packages listed to the latest version
(specified by the <code class="highlighter-rouge">tag</code> config), respecting semver.</p>

<p>It will also install missing packages. As with all commands that install
packages, the <code class="highlighter-rouge">--dev</code> flag will cause <code class="highlighter-rouge">devDependencies</code> to be processed
as well.</p>

<p>If the <code class="highlighter-rouge">-g</code> flag is specified, this command will update globally installed
packages.</p>

<p>If no package name is specified, all packages in the specified location (global
or local) will be updated.</p>

<p>As of <code class="highlighter-rouge">npm@2.6.1</code>, the <code class="highlighter-rouge">npm update</code> will only inspect top-level packages.
Prior versions of <code class="highlighter-rouge">npm</code> would also recursively inspect all dependencies.
To get the old behavior, use <code class="highlighter-rouge">npm --depth 9999 update</code>.</p>

<p>As of <code class="highlighter-rouge">npm@5.0.0</code>, the <code class="highlighter-rouge">npm update</code> will change <code class="highlighter-rouge">package.json</code> to save the 
new version as the minimum required dependency. To get the old behavior, 
use <code class="highlighter-rouge">npm update --no-save</code>.</p>

<h3 id="example">Example</h3>

<p>IMPORTANT VERSION NOTE: these examples assume <code class="highlighter-rouge">npm@2.6.1</code> or later.  For
older versions of <code class="highlighter-rouge">npm</code>, you must specify <code class="highlighter-rouge">--depth 0</code> to get the behavior
described below.</p>

<p>For the examples below, assume that the current package is <code class="highlighter-rouge">app</code> and it depends
on dependencies, <code class="highlighter-rouge">dep1</code> (<code class="highlighter-rouge">dep2</code>, .. etc.).  The published versions of <code class="highlighter-rouge">dep1</code> are:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nl">"dist-tags"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nl">"latest"</span><span class="p">:</span><span class="w"> </span><span class="s2">"1.2.2"</span><span class="w"> </span><span class="p">},</span><span class="w">
  </span><span class="nl">"versions"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
    </span><span class="s2">"1.2.2"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"1.2.1"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"1.2.0"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"1.1.2"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"1.1.1"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"1.0.0"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"0.4.1"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"0.4.0"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"0.2.0"</span><span class="w">
  </span><span class="p">]</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<h4 id="caret-dependencies">Caret Dependencies</h4>

<p>If <code class="highlighter-rouge">app</code>'s <code class="highlighter-rouge">package.json</code> contains:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nl">"dependencies"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="nl">"dep1"</span><span class="p">:</span><span class="w"> </span><span class="s2">"^1.1.1"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p>Then <code class="highlighter-rouge">npm update</code> will install <code class="highlighter-rouge">dep1@1.2.2</code>, because <code class="highlighter-rouge">1.2.2</code> is <code class="highlighter-rouge">latest</code> and
<code class="highlighter-rouge">1.2.2</code> satisfies <code class="highlighter-rouge">^1.1.1</code>.</p>

<h4 id="tilde-dependencies">Tilde Dependencies</h4>

<p>However, if <code class="highlighter-rouge">app</code>'s <code class="highlighter-rouge">package.json</code> contains:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nl">"dependencies"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="nl">"dep1"</span><span class="p">:</span><span class="w"> </span><span class="s2">"~1.1.1"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p>In this case, running <code class="highlighter-rouge">npm update</code> will install <code class="highlighter-rouge">dep1@1.1.2</code>.  Even though the <code class="highlighter-rouge">latest</code>
tag points to <code class="highlighter-rouge">1.2.2</code>, this version does not satisfy <code class="highlighter-rouge">~1.1.1</code>, which is equivalent
to <code class="highlighter-rouge">&gt;=1.1.1 &lt;1.2.0</code>.  So the highest-sorting version that satisfies <code class="highlighter-rouge">~1.1.1</code> is used,
which is <code class="highlighter-rouge">1.1.2</code>.</p>

<h4 id="caret-dependencies-below-100">Caret Dependencies below 1.0.0</h4>

<p>Suppose <code class="highlighter-rouge">app</code> has a caret dependency on a version below <code class="highlighter-rouge">1.0.0</code>, for example:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nl">"dependencies"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="nl">"dep1"</span><span class="p">:</span><span class="w"> </span><span class="s2">"^0.2.0"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p><code class="highlighter-rouge">npm update</code> will install <code class="highlighter-rouge">dep1@0.2.0</code>, because there are no other
versions which satisfy <code class="highlighter-rouge">^0.2.0</code>.</p>

<p>If the dependence were on <code class="highlighter-rouge">^0.4.0</code>:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nl">"dependencies"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="nl">"dep1"</span><span class="p">:</span><span class="w"> </span><span class="s2">"^0.4.0"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p>Then <code class="highlighter-rouge">npm update</code> will install <code class="highlighter-rouge">dep1@0.4.1</code>, because that is the highest-sorting
version that satisfies <code class="highlighter-rouge">^0.4.0</code> (<code class="highlighter-rouge">&gt;= 0.4.0 &lt;0.5.0</code>)</p>

<h4 id="updating-globally-installed-packages">Updating Globally-Installed Packages</h4>

<p><code class="highlighter-rouge">npm update -g</code> will apply the <code class="highlighter-rouge">update</code> action to each globally installed
package that is <code class="highlighter-rouge">outdated</code> – that is, has a version that is different from
<code class="highlighter-rouge">wanted</code>.</p>

<p>Note: Globally installed packages are treated as if they are installed with a caret semver range specified. So if you require to update to <code class="highlighter-rouge">latest</code> you may need to run <code class="highlighter-rouge">npm install -g [&lt;pkg&gt;...]</code></p>

<p>NOTE: If a package has been upgraded to a version newer than <code class="highlighter-rouge">latest</code>, it will
be <em>downgraded</em>.</p>

<h3 id="see-also">See Also</h3>

<ul>
  <li><a href="/cli-commands/install">npm install</a></li>
  <li><a href="/cli-commands/outdated">npm outdated</a></li>
  <li><a href="/cli-commands/shrinkwrap">npm shrinkwrap</a></li>
  <li><a href="/using-npm/registry">npm registry</a></li>
  <li><a href="/configuring-npm/folders">npm folders</a></li>
  <li><a href="/cli-commands/ls">npm ls</a></li>
</ul>
