0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Amazon Linux 2 に npm をインストールするときに libuv パッケージのバージョンエラーが出た

Last updated at Posted at 2023-01-06

状況

公式の Node インストール手順に従えば npm も同時にインストールされるはずだが、nvm で別の node バージョンに切り替えたら node のみ入っていて npm が入っていない状況になった。どうやってこういう状況になったのかは忘れた。

$ nvm --version
0.34.0

$ node -v
v17.8.0

$ npm -v
bash: npm: command not found

npm インストール時のエラー

$ sudo yum install npm

...

--> Finished Dependency Resolution
Error: Package: 1:nodejs-16.18.1-3.el7.x86_64 (epel)
           Requires: libuv >= 1:1.43.0
           Installed: 1:libuv-1.39.0-1.amzn2.x86_64 (@amzn2-core)
               libuv = 1:1.39.0-1.amzn2
           Available: 1:libuv-1.23.2-1.amzn2.0.2.i686 (amzn2-core)
               libuv = 1:1.23.2-1.amzn2.0.2
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

原因と対処法

sudo yum list libuv でみると、epel にも libuv はあるが amzn2-core の方が優先度が高いらしい。

stackoverflowのお兄さんの発言を試したら npm がインストールできた。

sudo yum remove libuv -y
sudo yum install libuv --disableplugin=priorities

--disableplugin=priorities がないとエラーが出ていても優先度高いリポジトリから持ってきてしまうらしい。
デフォルトでインストールされているパッケージのバージョンを無理やり変えることになるので他に影響がないとは言い切れないが。

おまけ (Node バージョンが古い理由)

Node バージョン 18, 19 を入れようとすると別のエラーになったため 17 にしている。

$ nvm install --lts
Installing latest LTS version.
v18.13.0 is already installed.
node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
nvm is not compatible with the npm config "prefix" option: currently set to ""

document に以下の記載がある。現時点で document の nvm のインストールコマンドのバージョンは 0.34.0 だが、リンクからレポジトリ見ると最新は 0.39.3 だったので、この辺の問題な気がする。

Warning
AWS does not control the following code. Before you run it, be sure to verify its authenticity and integrity. More information about this code can be found in the nvm GitHub repository.

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

しかし実際にnvmを0.39.3にしても結局 node 18以降はうまくいかなかった(npmが上記のエラーで動かない)

$ npm -v
node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)

GLIBC は Amazon Linux 2 には 2.26 までしか入っていないからだそう。
気付けば後継の Amazon Linux 2022 (AL2022) が出ており、こちらなら新しい GLIBC が入っていそうな雰囲気を感じたので、node 18以降を入れるならこちらを試すのがいいと思う。

Amazon Linux 2022 に関するよくある質問

Q: Amazon Linux 2022 とは何ですか?
A: Amazon Linux 2022 (AL2022) は、rpmベースの汎用Linuxディストリビューションで、Amazon Linux 2の後継にあたります。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?