<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>.:: Marcos Dione/StyXman's glob ::. (Posts about npm)</title><link>https://www.grulic.org.ar/~mdione/glob/</link><description></description><atom:link href="https://www.grulic.org.ar/~mdione/glob/categories/npm.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2025 &lt;a href="mailto:mdione@grulic.org.ar"&gt;Marcos Dione&lt;/a&gt; </copyright><lastBuildDate>Thu, 29 May 2025 15:41:11 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Installing npm on Debian testing</title><link>https://www.grulic.org.ar/~mdione/glob/posts/installing-npm-on-debian-testing/</link><dc:creator>Marcos Dione</dc:creator><description>&lt;p&gt;TL;DR: How lazy can you be? This post should take you 5 minutes to read... :-P&lt;/p&gt;
&lt;p&gt;So &lt;a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=857986"&gt;&lt;code&gt;npm&lt;/code&gt; is out of Debian testing&lt;/a&gt;.
This means that the hell that is &lt;code&gt;node&lt;/code&gt; code handling is now even harder.
&lt;a href="https://docs.npmjs.com/getting-started/installing-node"&gt;&lt;code&gt;node&lt;/code&gt;'s installation instructions&lt;/a&gt;
is a bloody video from which you can't even copy and paste the commands (how useful),
and as far as I can tell, it's the official way to install &lt;code&gt;npm&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you already have a good version of &lt;code&gt;node&lt;/code&gt; provided by your trusted
distribution, you most probably will cringe on the idea of installing a third
party package like this, and probably you don't think containers are the
solution, or you just want to install something locally so you can play with it.&lt;/p&gt;
&lt;p&gt;If you look closer to the bottom of that page you'll find the "advances user's"
guide to install it yourself, but it's only a pattern URL to the distribution &lt;code&gt;.tar.gz&lt;/code&gt;,
with no further instructions. With a little bit of luck, the instructions will
be included. The pattern has a placeholder for the version you want (putatively,
the latest), but I can't find, for the life of me, references to which is the
latest version.&lt;/p&gt;
&lt;p&gt;In the &lt;a href="https://github.com/npm/npm"&gt;GitHub project page&lt;/a&gt; you will find the
terrible, unluckily classic &lt;code&gt;curl https://site.com/unknown_script.sh | sh&lt;/code&gt;
command that downloads &lt;a href="https://www.npmjs.com/install.sh"&gt;this script&lt;/a&gt;. The
script is in POSIX shell dialect, and has strange constructions:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nv"&gt;node&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;which&lt;span class="w"&gt; &lt;/span&gt;node&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;span class="nv"&gt;ret&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$ret&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-eq&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-x&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$node&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To me, that &lt;code&gt;exit 0&lt;/code&gt; in a subshell is the equivalent of a NOOP, so I wonder why
they decided to write the condition like that.&lt;/p&gt;
&lt;p&gt;After checking the availability of a couple of tools (&lt;code&gt;node&lt;/code&gt;, &lt;code&gt;tar&lt;/code&gt;, &lt;code&gt;make&lt;/code&gt;,
but not &lt;code&gt;curl&lt;/code&gt;), it uses the latter to download JSON from the registry, finding
there the actual version (currently &lt;code&gt;4.5.0&lt;/code&gt;, if you're interested). It downloads
the package, untars it, and executes:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$node&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;cli.js&lt;span class="w"&gt; &lt;/span&gt;rm&lt;span class="w"&gt; &lt;/span&gt;npm&lt;span class="w"&gt; &lt;/span&gt;-gf
&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$node&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;cli.js&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;-gf
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The first removes any old installation. More on that in a minute. The
second, obviously, installs the new version. But the &lt;code&gt;-gf&lt;/code&gt; options (I hate short
options in scripts) are to be guessed, as no help is provided about them. Let's
go with &lt;code&gt;--global&lt;/code&gt; and &lt;code&gt;--force&lt;/code&gt;, which means it will install somewhere in your
system and overwriting anything it finds. With the previous command it should
have deleted all the files (same options), so you're really nuking whatever was
there before.&lt;/p&gt;
&lt;p&gt;Nowhere in the instructions so far says anything about &lt;code&gt;root&lt;/code&gt;, but obviously
this needs to be run as such. There's also
&lt;a href="https://www.npmjs.com/package/npm2#more-details"&gt;this detail&lt;/a&gt;:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nx"&gt;As&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m m-Double"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;is&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;recommended&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;allows&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;
&lt;span class="nx"&gt;change&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;identifier&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;nobody&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;prior&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;running&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;package&lt;/span&gt;
&lt;span class="nx"&gt;build&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;commands&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So there's no way to make a local installation of &lt;code&gt;npm&lt;/code&gt;... is there? Well, not
user wide, only system wide (already explained) and project wide. Here's how to
do the latter:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;$&lt;span class="w"&gt; &lt;/span&gt;wget&lt;span class="w"&gt; &lt;/span&gt;https://registry.npmjs.org/npm/-/npm-4.5.0.tgz
$&lt;span class="w"&gt; &lt;/span&gt;tar&lt;span class="w"&gt; &lt;/span&gt;xvf&lt;span class="w"&gt; &lt;/span&gt;npm-4.5.0.tgz&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# it's unpacked in a directory called 'package'&lt;/span&gt;
$&lt;span class="w"&gt; &lt;/span&gt;/usr/bin/node&lt;span class="w"&gt; &lt;/span&gt;package/cli.js&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;npm
$&lt;span class="w"&gt; &lt;/span&gt;rm&lt;span class="w"&gt; &lt;/span&gt;-rf&lt;span class="w"&gt; &lt;/span&gt;package&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# clean up after you!&lt;/span&gt;
$&lt;span class="w"&gt; &lt;/span&gt;./node_modules/.bin/npm&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;carto
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The third command uses the tarball's CLI interface to install the same version
'the right way'. To be honest, I had already used the old &lt;code&gt;npm&lt;/code&gt; version that used
to come with Debian to do exactly the same thing. Of course, this works as long
as newer version of &lt;code&gt;npm&lt;/code&gt; can still be installed with such an old version of the
same. Who knows when that's gonna break/be deprecated.&lt;/p&gt;
&lt;p&gt;All in all, it's sad to see such an useful tool be dropped like that. I just
hope someone can pick up the pieces.&lt;/p&gt;</description><category>debian</category><category>nodejs</category><category>npm</category><guid>https://www.grulic.org.ar/~mdione/glob/posts/installing-npm-on-debian-testing/</guid><pubDate>Thu, 04 May 2017 19:58:58 GMT</pubDate></item></channel></rss>