What Are the Differences Between Composer Update and Composer Install

What are the differences between composer update and composer install?

composer update

composer update will update your depencencies as they are specified in composer.json

For example, if you require this package as a dependency:

"mockery/mockery": "0.9.*",

and you have actually installed the 0.9.1 version of the package, running composer update will cause an upgrade of this package (for example to 0.9.2, if it's already been released)

in detail composer update will:

  • Read composer.json
  • Remove installed packages that are no more required in composer.json
  • Check the availability of the latest versions of your required packages
  • Install the latest versions of your packages
  • Update composer.lock to store the installed packages version

composer install

composer install will not update anything; it will just install all the dependencies as specified in the composer.lock file

In detail:

  • Check if composer.lock file exists (if not, it will run composer update and create it)
  • Read composer.lock file
  • Install the packages specified in the composer.lock file

When to install and when to update

  • composer update is mostly used in the 'development phase', to upgrade our project packages according to what we have specified in the composer.json file,

  • composer install is primarily used in the 'deploying phase' to install our application on a production server or on a testing environment, using the same dependencies stored in the composer.lock file created by composer update.

What is difference between composer update and composer upgrade ?

They are both the same command, upgrade is just an alias for update.

see UpdateCommand source:

class UpdateCommand extends BaseCommand
...
protected function configure()
{
$this
->setName('update')
->setAliases(array('u', 'upgrade'))
->setDescription('Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.')

(sets the command aliases)

compare composer list invocation:

$ composer list | grep '^ *\(update\|upgrade\|install\) '
install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
update Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
upgrade Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.

(the description is identical)

and composer composer update --help invocation:

$ composer update --help | sed -ne '1,/^$/p'
Usage:
update [options] [--] [<packages>]...
u
upgrade

(lists the command aliases)

Difference between composer update and composer global update

It's not anything to do with Yii directly.

Composer allows you to install dependencies globally or per-project (the default).

https://getcomposer.org/doc/03-cli.md#global

This is merely a helper to manage a project stored in a central location that can hold CLI tools or Composer plugins that you want to have available everywhere.

You might want to install something like phpunit or phpcs globally (so it's available for every project) whereas installing a library or framework that you need for your project should be a per-project installation.

difference between composer update and composer dump-autoload in laravel

composer update always regenerates composer.lock and installs the lastest versions of available packages based on composer.json

composer dump-autoload won’t download a thing. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php). Ideal for when you have a new class inside your project

difference between composer and composer.phar

There is no difference - composer.phar is the executable and composer can be an alias or symlink for it, depending on the way you've installed composer. As rob006 pointed out, there can be multiple ways to install composer: the official documentation at https://getcomposer.org/doc/00-intro.md#globally recommends to move the downloaded PHAR file to /usr/local/bin/composer which will make it callable through composer for all users of your system.

If you would move the file to another destination, like /usr/local/bin/composer.phar, the same composer binary would be available under that different command composer.phar.

And finally, if you would not have the chance to install composer globally, you could put it under either name in any local place

What are the differences between installing swiftmailer with Composer or apt?


$ composer require "swiftmailer/swiftmailer:^6.0"

Is system agnostic and will ensure that you will always have version >= 6.x.

It is also preferable for deployments on Docker where you may be using an -alpine image which does not have apt available.

Composer will also fail the entire install if it cannot satisfy that requirment, therefore ensuring that if your app is running it has SwiftMailer.

$ sudo apt-get install -y php-swiftmailer

Will install it on a system level, so long as that system is Debian based.

It will also install it in a "global" perspective, which may be more beneficial if you're going to have multiple applications on the same server.

You likely will not know if you can use SwiftMailer until you call the class/extention and the process fails.


In short, you'll probably want to prefer the Composer method.

what's the purpose of composer's `require` command

It's just a convention. There might be some fallbacks in other commands for common people missuses, but every command is optimized for a different feature. It's just better user experience.

Same goes for similarity of composer install and composer update.

As for conventions, in order of common workflow:

  • composer install is for installing all packages of new application (all mentioned in composer.json), use: composer install
  • composer require is for adding a new package, use: composer require symfony/symfony
  • composer update is for updating current dependencies, use: composer update

Differences between install via artisan and composer

The difference between both commands is that the composer command uses packagist to get the latest package from GitHub the first time or a cached version, while laravel new blog downloads a zip file from the Laravel server which has the latest version and uses that. Both commands run the so called 'after install' scripts, creating an environment file and setting the application key.

When you don't want a cached version but a new one using composer, run composer clear-cache first, to delete the local cache composer creates.

If you want to see the difference for yourself, compare the composer.json of the base Laravel project (https://www.github.com/laravel/laravel) and the NewCommand.php file in the src directory of the Laravel installer (https://www.github.com/laravel/installer)

Edit

After running both commands, the only difference I could really find was the order in which some things are done, but both generate a working system. Fun thing I noticed is that laravel new project comes with a yarn.lock file, but without a readme.md and composer composer create-project vice versa.



Related Topics



Leave a reply



Submit