最終更新:2023-10-06 (金) 15:25:58 (195d)  

npm install
Top / npm install

Install a package

npm install
npm install <package>

パラメータなし

  • package.jsonに記載されたパッケージが一括でインストールされる

パラメータ

  • The -g or --global argument will cause npm to install the package globally rather than locally. See npm help 5 npm-folders.

エイリアス

  • add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall

フォルダ

ローカル

  • npm bin
  • Local install (default): puts stuff in ./node_modules of the current package root.

グローバル

  • Global install (with -g): puts stuff in /usr/local or wherever node is installed.
  • npm bin -g
    C:\Users\<ユーザ名>\AppData\Roaming\npm

package.jsonへの追記

npm install

  • npm install saves any specified packages into dependencies by default. Additionally, you can control where and how they get saved with some additional flags:
    -P, --save-prodPackage will appear in your dependencies. This is the default unless -D or -O are present.
    -D, --save-devPackage will appear in your devDependencies.
    -O, --save-optionalPackage will appear in your optionalDependencies.
    --no-savePrevents saving to dependencies.

  • パッケージリストに保存
    npm install <パッケージ名> --save
  • By default with version npm 5.0+ npm install adds the module to the dependencies list in the package.json

npm install --save-dev

Ubuntuの場合

  • sudo npm install -g <パッケージ>

バージョン指定

npm updateとの違い

npm install

  • 未インストールのパッケージをインストール
  • 指定より上バージョンのパッケージが存在してもインストールしない

npm update

  • 未インストールのパッケージはインストールしない
  • 指定より上バージョンのパッケージが存在すればインストールする