【问题标题】:centOS can't install nodejs via yumcentOS无法通过yum安装nodejs
【发布时间】:2016-10-20 17:16:14
【问题描述】:

我在我的 centOS 服务器上使用 node v0.10.x,我想更新 node.js,所以关注了一些文章。首先删除当前安装的:

# which node
# cd /usr
# rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1

然后检查 node -v 没有工作,很好。但是使用 yum 并没有安装最新的 Node.js,所以我搜索了一些帖子,发现了这个: https://www.metachris.com/2015/10/how-to-install-nodejs-5-on-centos-and-ubuntu/

所以我遵循了命令:

# rpm -Uvh https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm
# yum install nodejs -y

这就是问题所在。它打印出许多错误并不断失败。

Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-4.el6 will be updated
--> Processing Dependency: nodejs(x86-64) = 0.10.42-4.el6 for package:     nodejs-devel-0.10.42-4.el6.x86_64
---> Package nodejs.x86_64 0:5.11.1-1nodesource.el7.centos will be an update
--> Running transaction check
---> Package nodejs-devel.x86_64 0:0.10.42-4.el6 will be updated
---> Package nodejs-devel.x86_64 0:5.11.1-1nodesource.el7.centos will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package         Arch      Version                          Repository     Size
================================================================================
Updating:
 nodejs          x86_64    5.11.1-1nodesource.el7.centos    nodesource    8.7 M
Updating for dependencies:
 nodejs-devel    x86_64    5.11.1-1nodesource.el7.centos    nodesource    7.6 M

Transaction Summary
================================================================================
Upgrade  1 Package (+1 Dependent package)

Total size: 16 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test


Transaction check error:
  file /usr/lib/node_modules/npm/node_modules/semver/package.json from install of nodejs-5.11.1-1nodesource.el7.centos.x86_64 conflicts with file from package nodejs-semver-2.1.0-1.el6.noarch
  file /usr/lib/node_modules/npm/node_modules/semver/bin/semver from     install of nodejs-5.11.1-1nodesource.el7.centos.x86_64 conflicts with file from package nodejs-semver-2.1.0-1.el6.noarch
  file /usr/lib/node_modules/npm/node_modules/semver/semver.js from install of nodejs-5.11.1-1nodesource.el7.centos.x86_64 conflicts with file from package nodejs-semver-2.1.0-1.el6.noarch
  ... and keeps going on ...

在删除节点之前,我也这样做了:

# npm cache clean -f
# npm install -g n
# n stable

但这根本不起作用,因为总是说版本 0.10.x,甚至下载了最新版本! (我锯过6.2.2什么的)

我认为我的服务器出了点问题,我不知道如何解决这个问题。任何人都可以给一些建议吗?如果可以的话,我想安装最新的 Node.js。

【问题讨论】:

  • 你可以尝试删除包nodejs-semver-2.1.0-1.el6.noarch
  • @J.J.Hakala find / -name nodejs-semver-2.1.0-1.el6.noarch 结果为空。那是一个文件吗?
  • @modernator,rpm 包不保存为包,它们被安装到目标(/usr/),然后从缓存中删除。 ...删除:#yum remove nodejs-semver ...

标签: node.js linux centos yum


【解决方案1】:

最简单的方法是使用“节点版本管理器nvm

在 shell 中,做:

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

注意如果您想在运行之前了解脚本,请阅读 nvm github page 上的文档和/或从 curl 中删除 | bash 无需运行 .sh 文件即可读取的命令

关闭并重新打开 shell 以使用更新的配置文件。那么:

//prints "nvm" if correctly installed
$ command -v nvm

// install latest version of node
$ nvm install node

//check it's installed correctly
$ node -v
v12.6.0

用其他方法失败后,这个没有问题。

【讨论】:

  • 安装后运行 source ~/.nvm/nvm.sh npm git get nvm 命令按预期工作
【解决方案2】:

首先,你必须安装 epe-release

sudo yum install epel-release

之后,就可以安装node.js和npm了

sudo yum -y install nodejs npm

它对我有用。

【讨论】:

【解决方案3】:

从 EPEL 存储库安装节点

yum update
yum install epel-release
yum install nodejs
node --version

访问 npm 来管理他们的 Node 包。

yum install npm

【讨论】:

  • 嗨@Haris 我得到No package epel-release 在上面运行命令时可用。
  • @NaveenKumar ,目前我在安装 nodejs 'No package epel-release' 时遇到同样的问题,你能解决这个问题吗?
  • @user3534759 是的,我直接从节点站点下载了包并添加到PATH中。
猜你喜欢
  • 1970-01-01
  • 2020-10-20
  • 2014-11-10
  • 1970-01-01
  • 2022-01-08
  • 1970-01-01
  • 2017-10-16
  • 2012-04-24
  • 2021-06-03
相关资源
最近更新 更多