LoginSignup
35
27

More than 5 years have passed since last update.

aws linuxにnpmを導入する

Last updated at Posted at 2019-03-02

今までなんとなく作業していたので、メモに残す

環境

aws linux

$ cat /etc/system-release
Amazon Linux AMI release 2018.03

インストールまとめ

# リポジトリの取得
$ curl -sL https://rpm.nodesource.com/setup_8.x | sudo bash -

# nodejsのインストール
$ sudo yum install -y nodejs

# 確認
$ npm -v

作業ログ

nodejsとnpmをインストール

sudo yum install nodejs npm --enablerepo=epel

npmのインストール完了。しかし、バージョンが古い。

$ npm -v
1.3.6

なので、バージョンアップする

npm install -g npm  

(-gはグローバルにするオプション)

しかし、下記エラーが発生

$ npm install -g npm                                                                                                                                                    
npm http GET https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm
npm ERR! Error: UNABLE_TO_GET_ISSUER_CERT_LOCALLY
npm ERR!     at SecurePair.<anonymous> (tls.js:1430:32)
npm ERR!     at SecurePair.emit (events.js:92:17)
npm ERR!     at SecurePair.maybeInitFinished (tls.js:1029:10)
npm ERR!     at CleartextStream.read [as _read] (tls.js:521:13)
npm ERR!     at CleartextStream.Readable.read (_stream_readable.js:341:10)
npm ERR!     at EncryptedStream.write [as _write] (tls.js:418:25)
npm ERR!     at doWrite (_stream_writable.js:226:10)
npm ERR!     at writeOrBuffer (_stream_writable.js:216:5)
npm ERR!     at EncryptedStream.Writable.write (_stream_writable.js:183:11)
npm ERR!     at write (_stream_readable.js:602:24)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 4.14.62-65.117.amzn1.x86_64
npm ERR! command "node" "/usr/bin/npm" "install" "-g" "npm"
npm ERR! cwd /home/ec2-user
npm ERR! node -v v0.10.48
npm ERR! npm -v 1.3.6
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/ec2-user/npm-debug.log
npm ERR! not ok code 0

ssl通信使用がonになっている生で発生している模様。下記コマンドでoffにする。
(参考 : https://stackoverflow.com/questions/45884752/npm-err-code-unable-to-get-issuer-cert-locally)

npm config set registry http://registry.npmjs.org/
# または、 npm config set strict-ssl false

その後、再実行。
※sudoつけるとコケるんでsudoはつけずに実行する。

バージョンを確認すると下記エラーが発生。

$ npm -v

/usr/lib/node_modules/npm/bin/npm-cli.js:84
      let notifier = require('update-notifier')({pkg})
          ^^^^^^^^
SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:945:3

epelでのインストールが原因の模様
(参考 : https://cpoint-lab.co.jp/article/201811/centos-7-%E3%81%A7epel%E3%83%AA%E3%83%9D%E3%82%B8%E3%83%88%E3%83%AA%E3%81%AEnpm%E3%81%A7%E3%82%A2%E3%83%83%E3%83%97%E3%83%87%E3%83%BC%E3%83%88%E3%82%92%E8%A1%8C%E3%81%86%E3%81%A8npm%E3%81%8C%E6%B6%88/)

よってリポジトリからインストールを行う。

一度アンインストール。

$ sudo yum -y remove npm

リポジトリの取得。

curl -sL https://rpm.nodesource.com/setup_8.x | sudo bash -

nodejsのインストールコマンドで完了する。

sudo yum install -y nodejs

バージョン確認

$ npm -v
6.4.1

作業完了。

35
27
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
35
27