Skip to content

Andrew Birck's Blog

Node 10 on Ubuntu 18

February 09, 2020

It has been awhile since I’ve a made a new post so I figured I’d write about a little issue I had with NodeJS on Ubuntu and how I went about solving it.

The engine “node” is incompatible with this module. Expected version ”>=10.x”. Got “8.10.0”

I was trying to run the setup for repository I had just cloned when I got an permissions error after running yarn installer (something about not being to start Docker which I had just installed). Since I had just installed Docker for this project I decided I should probably first make sure docker was up and running correctly. Following the Docker “Getting Started” guide I tried running the hello-world container but I got an error:

➜ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

Hm, permissions error. Let’s try a sudo:

➜ sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
<snip>

Tada. Okay, maybe I needed to run yarn installer as root since it messes with Docker and that’s when I got the error I wanted to talk about here:

➜ sudo yarn install
yarn install v1.21.1
[1/5] Validating package.json...
error: The engine "node" is incompatible with this module. Expected version ">=10.x". Got "8.10.0"
error Found incompatible module.

What’s going on

I knew I was using Node 10 so what’s going on? Well, I’d setup nvm a long time ago to manage node versions and had forgotten that nvm installs and manages node on a per-user basis. I was able to figure this out by comparing which version of node was found in the path for my user vs root:

➜ which node
/home/andrew/.nvm/versions/node/v10.19.0/bin/node
➜ sudo which node
/usr/bin/node

And the version at /usr/bin/node was indeed 8.10.0 which is crazy old. Just to make sure I checked the package that was installed:

➜ apt list --installed | grep node
nodejs/bionic-updates,now 8.10.0~dfsg-2ubuntu0.4 amd64 [installed]
nodejs-doc/bionic-updates,bionic-updates,now 8.10.0~dfsg-2ubuntu0.4 all [installed,automatic]

Which indeed showed I was using node 8.10.0. It seems kind of crazy to me the default version of Node installed with Ubuntu 18 (as of this writing the most recent LTS version) is running a node version that is no longer maintained but an apt upgrade didn’t show any upgrades available for the package.

What I did

I took the shortcut method because I was just trying to hack stuff and make it work. I copied the Node 10 binaries to a system-wide location where they’d take precedence over the ancient ones installed by apt. Someone else had already put together a neat little command-line that would find the Node version you were currently using and copy it to /usr/local/bin (which comes before /usr/bin in my path and thus would take precedence):

➜ echo $PATH
/home/andrew/.nvm/versions/node/v10.19.0/bin:/home/andrew/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
➜ n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
<stuff>
➜ which node
/usr/local/bin/node
➜ /usr/local/bin/node -v
v10.19.0

And running my sudo yarn installer command worked!

A better way

Probably a better way to do things is actually replace that old package with a new one so the old binaries aren’t even sitting around any more. Another benefit to using packages is if you need to switch back to Node 8 for some reason, switching packages is probably easier than hunting around in /usr/local and manually removing the binaries we copied there.

Once again I found someone who had written about using a personal package archive (PPA) maintained by NodeSource to replace the official packages. First install the new PPA:

➜ curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
➜ sudo bash nodesource_setup.sh
<a bunch of apt-get output>

Then just upgrade the package:

➜ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
Use 'sudo apt autoremove' to remove them.
The following packages will be upgraded:
nodejs
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 16.2 MB of archives.
After this operation, 62.6 MB of additional disk space will be used.
Do you want to continue? [Y/n]

After installing the version of node used by root (under /usr/bin) is upgrade to Node 10!

➜ sudo which node
/usr/bin/node
➜ sudo node -v
v10.19.0

What if I need to go back

You can just remove the Node package archive from your source list:

➜ sudo ls /etc/apt/sources.list.d
alessandro-strada-ubuntu-ppa-bionic.list nodesource.list yarn.list.save
alessandro-strada-ubuntu-ppa-bionic.list.save yarn.list
➜ sudo rm -i /etc/apt/sources.list.d/nodesource.list
rm: remove regular file '/etc/apt/sources.list.d/nodesource.list'? y

And then remove/install the Node package again:

➜ sudo apt-get purge nodejs
<snip>
➜ sudo apt install nodejs
<snip>
➜ sudo node -v
v8.10.0

Andrew Birck
A place to for me to post stuff (mostly)
about software development.