DEV Community


Being Wrong and Happy For Four Month

Jay R. Wren
jamming with the cowboys in cyberspace since 1995 coding basic on Atari 800XL since 1985
・2 min read


Yesterday, I wanted to use node and npm to write something. This is something I rarely do. I wanted to use it on an old server running ubuntu. I ran node. It was there. I ran npm. It was no there. I checked the node binary and the deb package from which it came. It was from the ubuntu 18.04 repo. I could either apt install npm to get an old version of npm, or I could upgrade the node from the ubuntu repo to the nodesource repo which includes a newer npm. I chose the later.

This is where my enlightenment began.

Four months ago I was happy to see that the apt update command was no longer required after running add-apt-repository. When I read it on I thought that '-u' was now the default behavior. That would be the most efficient way to implement this feature. I had jumped to conclusions.

Let me back up 3 years.

I was working on a cloud deployment tool which deployed many new ubuntu images and installed things on them. This meant a lot of apt-get update and add-apt-repository calls. It was slow. It was even slower when run on a cloud with slow internet and non-local repositories. All of those http roundtrips to remote servers to fetch the same results from apt-get update was driving me mad. I don't like slow things. There had to be a way to speed things up.

I wrote the '-u' feature to add-apt-repository, I submitted it, and it was accepted with thanks. I was very happy. I felt that I'd made the world a better place, even if only a tiny bit for some of us techie folks. The '-u' feature works by fetching and merging the new package information only for the newly added repository instead of for ALL repositories like apt-get update does. It can shave a minute or more from a deploy which adds repositories, couple that with a deploy which uses multiple machines or system containers and it multiplies.

Back to yesterday with npm.

I ran the add-apt-repository command without -u, because it shouldn't be needed, or so I thought...

sudo add-apt-repository 'deb bionic main'
Enter fullscreen mode Exit fullscreen mode


It was very slow.

It turns out my conclusion that -u was default is wrong. A full (usually needless) apt-get update is now the default. ugh. disappointment.

Conclusion: continue to use '-u' with add-apt-repository.


I use these commands to get nodejs on an ubuntu bionic system. The node_8.x can be changed to node_10.x for the 10.x repo. bionic can be any of stretch, jessie, buster, sid, trusty, xenial, precise. * I think some combinations may not work, but as long as you are on new enough distro, the newer node repos from nodesource will work.

curl -s | sudo apt-key add -
sudo add-apt-repository -u 'deb bionic main'
sudo apt purge npm # may not be required if it is not already installed.
sudo apt install nodejs
Enter fullscreen mode Exit fullscreen mode

Discussion (0)