node.jsrpmyum

Why does yum not read updates to RPM repository file?


On Amazon Linux, I was following the guide of installing Node.js v16 via NodeSource RPM:

$ curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash

The command above updates the repository file in /etc/yum/yum.repos.d/nodesource-el7.repo, such that when I run yum list --showduplicates nodejs, yum shows me all available version 16 of Node.js. No problem here.

But then, I decided to install v20 instead. So I run the command below, modifying yet again the /etc/yum/yum.repos.d/nodesource-el7.rep. This should let yum discover v20 distributions of Node.js:

curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -

The problem is, when I try to install Node.js v20 using sudo yum install nodejs, yum installs v16 instead. When I run yum list --showduplicates nodejs, yum still shows me the list of v16 Node.js, and not v20. It's as if yum doesn't know that the .repo was updated.

I try to use yum clean all in hopes for yum to discover the v20 Node.js repository, but it doesn't work. I used yum clean metadata and it worked for only a couple of times. As I kept experimenting by switching between v16 and v20 installations, in the end yum list nodejs rarely updates its list despite updates to the Node.js .repo.

Question: how do I tell yum to update its discoverable packages according to updates in /etc/yum.repos.d/? (The nodesource-el7.repo in my case.)


Solution

  • After trying out different things, scouring the docs and going through a lot of trouble in the process, it seems that the command below is a fool-proof way to ensure that Yum reads its repositories correctly.

    sudo rm -rf /var/cache/yum && yum clean all && yum makecache