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.)
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
yum clean all
cleans all sorts of temporary files.yum makecache
recreates the Yum cache. It seems that yum clean all
does not clear caches on the HTTP layer, and this command fixes that.rm -rf /var/cache/yum
is to somehow fix the inconsistency brought by the previous 2 commands above. That is, the version displayed in yum list <package>
can differ from the version installed via yum install <package>
. Deleting the cache directory somehow fixes this.