Unable to self-update composer?

后端 未结 6 1561
失恋的感觉
失恋的感觉 2020-12-14 05:39

I am trying to update composer with no luck!

What I have tried:

$ composer self-update

[InvalidArgumentException]

相关标签:
6条回答
  • 2020-12-14 06:11

    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') === 'c31c1e292ad7be5f49291169c0ac8f683499effffdcfd4e42232982d0fd193004208a58ff6f353fde0012d35fdd72bc394') { 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 no need to use sudo prefix:

    composer self-update
    
    0 讨论(0)
  • 2020-12-14 06:14

    As @Waqleh said, you have to uninstall 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 composer.phar to a directory that is in your path (fom https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx):

    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 IDE's) you'll have to close it and open again.

    0 讨论(0)
  • 2020-12-14 06:19

    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.

    0 讨论(0)
  • 2020-12-14 06:19

    you can specify installation directory and filename while setting up composer - php composer-setup.php like so:

    sudo php composer-setup.php --install-dir=/usr/bin --filename=composer
    
    0 讨论(0)
  • 2020-12-14 06:26

    I've installed brew and it saves me a lot. Install brew then brew install composer to install the composer.

    0 讨论(0)
  • 2020-12-14 06:27

    Install the latest Composer by 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 /usr/bin dir 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
    
    0 讨论(0)
提交回复
热议问题