Composer auto self-update
Asked Answered
M

9

32

It is frequently that every 30 days I will get this warning message:

Warning: This development build of composer is over 30 days old. It is recommended to update it by running "composer.phar self-update" to get the latest version.

Then, I have to repeatedly do the update every 30 days. Is there anyway I can have the composer to auto update itself?

Thank you.

Mcginley answered 18/7, 2014 at 2:21 Comment(0)
A
39

Composer doesn't have a feature to automatically run self-update to my knowledge. Also, running self-update by itself doesn't seem like the right way. Maybe you don't have permission? Then try using sudo, like: sudo composer self-update.

It is just a simple command, and you should only need to do it once about every 30 days. And keep Composer installed globally so you don't need to run it for each project.

Abaddon answered 18/7, 2014 at 8:3 Comment(2)
Note that self-update is not available on older composer versions (e.g. installed version 1.0.0-beta2 on Ubuntu 16.4) Also (from the composer manual): If you have installed Composer for your entire system, you may have to run the command with root privileges: sudo -H composer self-updateHarden
Pretty strange that this command isn't listed in the --helpStillas
S
35

For versions of composer which self-update is not yet available, just run the following commands:

  1. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');". This will download the composer-setup.php file into the current working directory;
  2. php composer-setup.php. This will create the composer.phar file into the current working directory;
  3. sudo mv composer.phar `which composer` . Replace the installed composer executable (in my case /usr/bin/composer) with the one from the previous step.

After you've done this steps the sudo composer self-update will become available.

Surfactant answered 11/8, 2020 at 21:16 Comment(1)
this made my day thanks :)Fernandofernas
P
13
composer self-update --2

solved my problem. (upgraded to 2.1.3)

Putnam answered 1/7, 2021 at 7:3 Comment(0)
L
3

Composer is still in development. There have been alpha versions released, but there still is no foreseeable date for the first stable release.

So running composer self-update is always installing the most recent commit from the Github repository. Expect these commits to be broken! If you can live with your automatic update to constantly install broken versions of Composer, just create a cronjob running once every month or more often.

If you think that there is too much risk doing this, then update manually and check if everything still works.

Laveen answered 19/7, 2014 at 10:43 Comment(0)
H
1

Put the composer self update command in a bash file and execute from a cron job.

This link has a good discussion and explanation about how to use cron: https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job

The most basic explanation would put the shell script in this folder: /etc/cron.monthly.

Hydraulics answered 22/8, 2014 at 12:0 Comment(0)
H
0

For me the solutions was actually going to one of the following directories: cd / or cd ~ or cd /usr/share on Ubuntu WSL2. For some reason i wasn't able to update in certain folders like www.

I combined this with sudo composer self-update 1 or (2) to get it working.

Heft answered 10/11, 2021 at 9:17 Comment(0)
I
0

For the record in Ubuntu 20-22 but I think it is also valid for other distros:

If you install via apt, then you only get version 2.26 (the current version to date is 2.5)

  • So, you must uninstall it
sudo apt-get remove composer -y
  • and install it manually:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/bin --filename=composer
  • And finally you can check as
composer --version

If it doesn't show the correct version, then you must run

sudo composer self-update --2
# it will show Composer version 2.5.4 2023-02-15 13:10:06
Interlocution answered 12/3, 2023 at 12:23 Comment(0)
T
0

You can check this link here https://serverpilot.io/docs/how-to-downgrade-to-composer-version-1/
To avoid the auto update sudo apt-mark hold sp-composer

Typescript answered 22/5 at 16:32 Comment(0)
P
-2

try the following command.

sudo composer self-update

It worked for me!

Polygynous answered 17/10, 2017 at 6:16 Comment(1)
This is correct for more recent versions of composer, but for some versions for example installed with package managers do not have the self-update parameter.Why

© 2022 - 2024 — McMap. All rights reserved.