下午需要帮研发在一台centos7服务器上安装nodejs,图简单,直接yum install nodejs,结果报错如下:
Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable <repoid> or subscription-manager repos --disable=<repoid> 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true Cannot find a valid baseurl for repo: centos-sclo-sclo
其实只需要看最后一句关键信息“Cannot find a valid baseurl for repo: centos-sclo-sclo”,也不知道这是谁弄的,去/etc/yum.repos.d/下果然看到了相关的源,主要是也不能轻易删除,最终经过一顿大模型搜索,发现用下面几条命令可以轻松解决:
1、首先列出所有已启用的仓库: yum repolist 2、根据报错信息,centos-sclo-sclo 仓库出现了问题。可以尝试禁用它: yum --disablerepo=centos-sclo-sclo install -y nodejs 3、如果不确定有哪些仓库报错,可以尝试临时禁用所有仓库来安装软件。运行以下命令: yum --disablerepo='*' --enablerepo='nodesource-nodejs' install -y nodejs 上面的仓库是我提供装好了的,命令如下: curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
这招非常好用,以后再也不怕yum安装出错了。