Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install vs. update - what's the difference?

Tags:

node.js

npm

What is the practical difference between npm install and npm update? When should I use which?

like image 394
Borek Bernard Avatar asked Sep 18 '12 14:09

Borek Bernard


People also ask

What is the difference between npm install and npm install?

npm install , or npm i , is used to install dependencies: It will install all the dependencies. If you use ^ or ~ when you specify the version of your dependency, npm may not install the exact version you specified. npm install can update your package-lock.

Is it necessary to update npm?

When you run npm update, npm checks if there exist newer versions in the repository that satisfy specified semantic versioning ranges and installs them. I would say "bite the bullet" and update them to latest. It will be a tedious task but if you are looking to maintain this for longer run, it is your best bet.

Is npm I the same as install?

There is no difference, since "npm i" is an alias for "npm install". They both do the exact same thing (install or update all the dependencies in your package-lock.

Whats difference between npm I install and npm I install -- save?

It has a very frequently used command npm install [Package Name] –save. But the fact is there is no difference between npm install [Package Name] and npm install [Package Name] –save in the later version after npm 5.0. 0 onwards.


2 Answers

The difference between npm install and npm update handling of package versions specified in package.json:

{   "name":          "my-project",   "version":       "1.0",                             // install   update   "dependencies":  {                                  // ------------------     "already-installed-versionless-module":  "*",     // ignores   "1.0" -> "1.1"     "already-installed-semver-module":       "^1.4.3" // ignores   "1.4.3" -> "1.5.2"     "already-installed-versioned-module":    "3.4.1"  // ignores   ignores     "not-yet-installed-versionless-module":  "*",     // installs  installs     "not-yet-installed-semver-module":       "^4.2.1" // installs  installs     "not-yet-installed-versioned-module":    "2.7.8"  // installs  installs   } } 

Summary: The only big difference is that an already installed module with fuzzy versioning ...

  • gets ignored by npm install
  • gets updated by npm update

Additionally: install and update by default handle devDependencies differently

  • npm install will install/update devDependencies unless --production flag is added
  • npm update will ignore devDependencies unless --dev flag is added

Why use npm install at all?

Because npm install does more when you look besides handling your dependencies in package.json. As you can see in npm install you can ...

  • manually install node-modules
  • set them as global (which puts them in the shell's PATH) using npm install -g <name>
  • install certain versions described by git tags
  • install from a git url
  • force a reinstall with --force
like image 64
AlexGrafe Avatar answered Sep 28 '22 01:09

AlexGrafe


npm install installs all modules that are listed on package.json file and their dependencies.

npm update updates all packages in the node_modules directory and their dependencies.

npm install express installs only the express module and its dependencies.

npm update express updates express module (starting with [email protected], it doesn't update its dependencies).

So updates are for when you already have the module and wish to get the new version.

like image 43
saeed Avatar answered Sep 28 '22 02:09

saeed