LoginSignup
6

More than 5 years have passed since last update.

npmをバージョン指定してインストールする

Last updated at Posted at 2017-04-26

はじめに

Dockerでnpmを使っていたのですがエラーが出てしまいました。

$ npm install --global npm@4.5.0
$ npm --version


module.js:471
    throw err;
    ^

Error: Cannot find module 'semver'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/unsupported.js:2:14)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

npmの最新版(安定版?)を入れる方法があったのですがうまく動かず、バージョン指定で入れることができないかな、ということで試してみました。

バージョン4.5.0のインストール
$ curl -0 -L https://registry.npmjs.org/npm/-/npm-4.5.0.tgz | tar zxvf - && \
 cd package && ./configure && make && make install
バージョン3.10.10のインストール
$ curl -0 -L https://registry.npmjs.org/npm/-/npm-3.10.10.tgz | tar zxvf && \
 cd package && ./configure && make && make install

The npm module is available for download at https://registry.npmjs.org/npm/-/npm-{VERSION}.tgz.
https://docs.npmjs.com/getting-started/installing-node

インストールスクリプト

あちこちにインストールスクリプトを使う方法が載っていて、そちらでのやり方です。

$ curl -0 -L https://npmjs.org/install.sh | sh

サイトによっては記述されていない、リダイレクトを追跡する-Lオプションが必要でした。
おそらくですがNode.jsのバージョンに適したnpmが入るのではないかな、と思います。Node.jsの6.10.2ではnpmの3.10.10が入りました。

参考サイト

http://hayatomo.com/2220
http://hacknote.jp/archives/17889/
http://qiita.com/aureonebulosa/items/1cbfacc8a8095f2ee887

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
6