How to Install Composer on Ubuntu 22.04

3

If you’re the usage of PHP in your Ubuntu 22.04 components, it’s possible you’ll want to set up Composer someday. Composer is a PHP dependency supervisor that mean you can set up your venture’s dependencies in a very easy and environment friendly means. In this information, we’ll display you tips on how to set up Composer in your Ubuntu components.

Prerequisites

  • Shell get right of entry to to a operating Ubuntu components.
  • Install PHP 5.3 or upper edition.

Installing PHP Composer on Ubuntu

The Composer’s reliable group supplies a script to put in PHP composer on Linux programs. You can obtain this script the usage of the curl or wget command-line software. Also, you’ll obtain it without delay the usage of the PHP script command line.

  1. To obtain the composer-setup script, run the next command in a terminal:
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 
    
  2. Then execute the downloaded PHP script to put in the composer in your Ubuntu components on the desired location. Use --install-dir to set the binary location and --filename to set the binary title. You can make a choice one of the vital underneath possibility:
    • Installing PHP composer system-wide: This will set up composer in /uer/native/bin listing, this is obtainable to all customers:
      sudo php composer-setup.php --install-dir=/usr/native/bin --filename=composer
      sudo chmod +x /usr/native/bin/composer
      
    • Installing PHP composer for explicit applicaiton: Sometimes you dont’ have permission to put in it globally, like shared internet hosting account. Then you’ll configure this beneath you software as smartly. To set up composer in the neighborhood sort:
      cd /trail/to/php-application && mkdir -p bin 
      php composer-setup.php --install-dir=bin --filename=composer
      chmod +x bin/composer
      

      Make certain to interchange /trail/to/php-application together with your software listing.

  3. To see the put in composer edition execute binary with -v command parameter.
    composer --version
    

    Output:

    Composer edition 2.3.7 2022-06-06 16:43:28

Upgrade PHP Composer

The PHP composer has the facility to self-upgrade to the newest variations. If the composer is already put in in your components, simply sort the underneath command to improve the PHP composer to the newest edition.

composer self-update

In my case, I have already got newest edition of composer. So obtain the next message on terminal:

Output:

You are already the usage of the newest to be had Composer edition 2.3.7 (strong channel).

Working with PHP Composer

You have already put in and configured the composer in your components. The composer will let you to control modules on your software. For instance, to put in a brand new module on your software.

Switch to the PHP software.

cd /trail/to/php-application 

Run the next command to put in psr/log module within the software.

composer require psr/log

Output:

Using edition ^3.0 for psr/log ./composer.json has been created Running composer replace psr/log Loading composer repositories with package deal knowledge Updating dependencies Lock report operations: 1 set up, 0 updates, 0 removals - Locking psr/log (3.0.0) Writing lock report Installing dependencies from lock report (together with require-dev) Package operations: 1 set up, 0 updates, 0 removals - Downloading psr/log (3.0.0) - Installing psr/log (3.0.0): Extracting archive Generating autoload recordsdata

Composer will routinely create or replace composer.json report at software root listing. Now, the applying can use the capability supplied by means of the module.

The above command will set up the newest edition of the module. You too can outline the module edition you need to put in on your software. If the module is already put in, it’s going to routinely downgrade/improve the package deal to the desired edition.

composer require psr/log=1.0

The module now not required will also be got rid of with the next command.

composer take away psr/log

All the above instructions additionally replace composer.json report accordingly.

Conclusion

In this instructional, you’ve discovered directions to put in composer on Ubuntu 22.04 (Jammy Jellyfish) components. You can set up composer globally to permit get right of entry to to all customers and packages. Also, you’ll set up composer for a selected listing.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More