LoginSignup
53
31

More than 5 years have passed since last update.

yumでのnodejsのバージョンアップにはまった話と解決方法

Posted at

nodejsのバージョンアップではまったことがあったので、発生した問題の再現方法と、原因および解決方法について。

問題発生環境

  • CentOS 6
    • CentOS release 6.9 (Final)
    • yum - 3.2.29
  • CentOS 7
    • CentOS Linux release 7.4.1708 (Core)
    • yum - 3.4.3

他のOSなどでも起こるかもしれませんが確認していません。

再現方法の検証はnodejs6と7でやってますが、別バージョンのnodejsでも同様の方法で導入した場合には同じ問題が起こります。

問題1:新しいバージョンのnodejsが入らない

再現方法

とりあえずrootになっときます。
※sudoでやってても起こりますが、私がsudoよく付け忘れるという理由による。

$ sudo su -

本家サイトにも書いてあるお作法で、まずはrpmを取得します。

$ curl --silent --location https://rpm.nodesource.com/setup_6.x | bash 
$ curl --silent --location https://rpm.nodesource.com/setup_7.x | bash 

再現の便宜上、上記ではrpmを連続で2つ取得していますが、7.x(新しいほう)を入れたいものとします。

しかしこの時、このままyumでinstallすると

$ sudo yum -y install nodejs

入るのは6系です。(・ω・ )

$ node -v
v6.12.3

原因と解決方法

要はnodejsのrpmが2つできて、しかも意図せず古いほうのバージョンが優先されてしまっているわけです。

$ ll /etc/yum.repos.d/ | grep node
-rw-r--r--. 1 root root 472 Oct 21  2016 nodesource-el6.repo
-rw-r--r--. 1 root root 472 Apr 26  2016 nodesource-el.repo

$ cat /etc/yum.repos.d/nodesource-el.repo 
[nodesource]
name=Node.js Packages for Enterprise Linux 6 - $basearch
baseurl=https://rpm.nodesource.com/pub_6.x/el/6/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL

[nodesource-source]
name=Node.js for Enterprise Linux 6 - $basearch - Source
baseurl=https://rpm.nodesource.com/pub_6.x/el/6/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
gpgcheck=1

なので、古い方のrpm、削除しちゃいましょう。

$ rm /etc/yum.repos.d/nodesource-el.repo

そして問題2に続きます。

問題2:インストール中ダウンロードでエラーが起こる

問題1から引き続きます。

再現方法

問題1から引き続いた状態で、とりあえず7系を入れるために今あるnodejsはremoveします。

$ yum -y remove nodejs

そして改めてinstallします。

$ yum -y install nodejs

するとエラーが起こります。(・ω・ )

Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 2:6.12.3-1nodesource will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================
 Package               Arch                  Version                                Repository                 Size
====================================================================================================================
Installing:
 nodejs                x86_64                2:6.12.3-1nodesource                   nodesource                 13 M

Transaction Summary
====================================================================================================================
Install       1 Package(s)

Total download size: 13 M
Installed size: 38 M
Downloading Packages:
https://rpm.nodesource.com/pub_7.x/el/6/x86_64/nodejs-6.12.3-1nodesource.x86_64.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
To address this issue please refer to the below knowledge base article 

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.



Error Downloading Packages:
  2:nodejs-6.12.3-1nodesource.x86_64: failure: nodejs-6.12.3-1nodesource.x86_64.rpm from nodesource: [Errno 256] No more mirrors to try.

原因と解決方法

エラーメッセージをよくよく見るとわかるんですが、 nodejs7.x用のURLにnodejs6.xの情報を問い合わせにいっている ので、 そんな情報ねえよってエラー(404 Not Found) が出ているのです。そりゃそうです。

というわけでなんか色々をクリアできるらしいコマンド打ちます。

$ yum clean all

再びインストールしなおします。

$ yum -y install nodejs

成功(・∀・)

$ node -v
v7.10.1

補足

  • rpmの優先度の管理を、ファイルを直接触らずちゃんとコマンド経由などでやっていれば(そういうことができるのかどうかなどは調べていませんが)、もしかしたら問題2は起こらなかったのかなあなどとも思います。
  • ただ、rpmファイルの直接操作などしなくても問題2が起こる場合もありました。
    • 操作ミスなども含む微妙な違いで起こったり起こらなかったりしたので、再現方法の特定はあきらめました。

参考

他にも色々参考にしたところがあったはずなんですが情報どっかにいっちゃったのでメモっていたところだけ。ありがとうございました!

53
31
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
53
31