无法自动更新作曲器

我试图更新作曲家没有任何运气!

我所尝试的:

$ composer self-update

[ InvalidArgumentException ] 没有定义命令“ self-update”。

$ sudo -H composer self-update

[ InvalidArgumentException ] 没有定义命令“ self-update”。

$ sudo apt-get install composer

阅读软件包列表... 完成构建依赖树阅读 已完成的作曲家已经是最新的版本 以下软件包已自动安装,不再 必需: libntdb1 linux-headers-4.2.0-30 Linux-headers-4.2.0-30-general linux-image-4.2.0-30-general Linux-image-plus-4.2.0-30-general python-ntdb 使用‘ apt-get 0升级,0新安装,0删除 还有10个没升级。

我试图自我更新作曲家,因为我面临下列每一次我尝试:

$ composer update

用包信息加载编写器存储库更新 依赖关系(包括 request-dev) [ RuntimeException ] 中无法加载包 rmrevin/yii2-fontawes Http://packagist.org : [意外值异常]无法解析 版本限制 v4.1. : 无效的版本字符串“ v4.1。” [意外值异常] 无法解析版本约束 v4.1。 < em > : 无效的版本字符串 “ v4.1. ”

我怎样才能解决这个问题?

我的 PHP 版本是:

php --version

PHP 5.6.11-1ubuntu3.4(cli)版权(c)1997-2015 Zend Engine v2.6.0,版权(c)1998-2015年 Zend Technologies 使用 Zend OPcache v7.0.6-dev,版权(c)1999-2015,Zend Technologies

我的作曲家版本是:

composer --version

作曲家 version@package _ Branch _ alias _ version@(@package _ version@) @ release _ date@

160615 次浏览

Since I posted my answer, I have learnt a new easier way to install Composer programmatically: How do I install Composer programmatically?

Old Answer:


As per @JimL comment, I was able to self update Composer by:

  • Uninstalling Composer from the package manager (apt).
  • I installed it according to the official documentation

Now it works as expected.

As Waqleh said, you have to uninstall PHP Composer and install it again. First, execute:

sudo apt-get remove composer

Then, execute these commands. The checksum here is for Composer 1.10.13, but you'll get the newest Composer (2.0.4 at the moment of editing this answer) when running the first line, so be sure to check in https://getcomposer.org/download/:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '8a6138e2a05a8c28539c9f0fb361159823655d7ad2deecb371b04a83966c61223adc522b0189079e3e9e277cd72b8897') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Now move file composer.phar to a directory that is in your path (from Installation - Linux / Unix / macOS):

sudo mv composer.phar /usr/local/bin/composer

And execute composer from any directory. That's all!

PS: If you're using PhpStorm (or maybe other IDEs), you'll have to close it and open it again.

Install the latest version:

Remove your current Composer version, for example Ubuntu/Debian:

sudo apt-get remove composer

Now, head to https://getcomposer.org/download/ and paste the script in your command line. This ensures that you get the latest version of Composer (as time of writing: v2.0.7).

Like this:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"

After some time passed, you can update and there isn't any need to use the sudo prefix:

composer self-update

I've installed Homebrew and it saves me a lot.

Install brew and then brew install composer to install Composer.

You can specify the installation directory and filename while setting up PHP Composer - php composer-setup.php like so:

sudo php composer-setup.php --install-dir=/usr/bin --filename=composer

Install the latest Composer by the following steps:

Uninstalling Composer

sudo apt-get remove composer

Run following commands

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '8a6138e2a05a8c28539c9f0fb361159823655d7ad2deecb371b04a83966c61223adc522b0189079e3e9e277cd72b8897') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php

Install Composer in the /usr/bin directory to run Composer from anywhere

sudo php composer-setup.php --install-dir=/usr/bin --filename=composer

Remove the installer

php -r "unlink('composer-setup.php');"

To check or self update

composer self-update

If you have an old version of Composer you need to follow these commands:

composer -V
sudo apt remove composer
cd /tmp
wget http://getcomposer.org/download/1.10.5/composer.phar


php composer.phar -V
sudo mv composer.phar /usr/bin/composer
sudo chmod 750 /usr/bin/composer
composer -V

It worked for me (linux, Ubuntu 20.04):

sudo apt-get remove composer
sudo apt-get update
sudo apt-get install curl
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Already there are many answers, Would like to share my experience with this.

I am using Ubuntu 20.04, and My previous Composer version was Composer 2.0.11 and my Project requirement was Composer 2.1.15.

I didn't had to remove anything, I simply used the following command and it worked fine for me :)

Composer Update

composer 2 on debian :

cd /usr/src


sudo apt-get install curl php7.2-cli


curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer


chmod 777 composer


nano ~/.bashrc

add : PATH=$PATH/usr/local/bin/

source ~/.bashrc

verify :composer -v

Composer self-update may not work for others and using the documentation from the composer may be confusing for some. The following steps may help reinstall the composer to solve the problem.

#update the package manager

sudo apt update

#install the required packages

sudo apt install php-cli unzip

#retrieve the installer

curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php

#obtain the latest hash from the Composer page

HASH=`curl -sS https://composer.github.io/installer.sig`
echo $HASH #verify the obtained value

#verify that the installation script safety

php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

#installing composer globally

sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer

#test your installation

composer

That's it. Credit: Erika Heidi