Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Distributions»Ubuntu»How to Install Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    RahulBy RahulJune 22, 20223 Mins ReadUpdated:June 24, 2022

    If you’re using PHP on your Ubuntu 22.04 system, you may need to install Composer at some point. Composer is a PHP dependency manager that can help you manage your project’s dependencies in an easy and efficient way. In this guide, we’ll show you how to install Composer on your Ubuntu system.

    Prerequisites

    • Shell access to a running Ubuntu system.
    • Install PHP 5.3 or higher version.

    Installing PHP Composer on Ubuntu

    The Composer’s official team provides a script to install PHP composer on Linux systems. You can download this script using the curl or wget command-line utility. Also, you can download it directly using the PHP script command line.

    1. To download the composer-setup script, run the following command in a terminal:
      php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 
      
    2. Then execute the downloaded PHP script to install the composer on your Ubuntu system at the desired location. Use --install-dir to set the binary location and --filename to set the binary name. You can choose one of the below option:
      • Installing PHP composer system-wide: This will install composer in /uer/local/bin directory, that is accessible to all users:
        sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
        sudo chmod +x /usr/local/bin/composer
        
      • Installing PHP composer for specific applicaiton: Sometimes you dont’ have permission to install it globally, like shared hosting account. Then you can configure this under you application as well. To install composer locally type:
        cd /path/to/php-application && mkdir -p bin 
        php composer-setup.php --install-dir=bin --filename=composer
        chmod +x bin/composer
        

        Make sure to replace /path/to/php-application with your application directory.

    3. To see the installed composer version execute binary with -v command parameter.
      composer --version
      
      Output:
      Composer version 2.3.7 2022-06-06 16:43:28

    Upgrade PHP Composer

    The PHP composer has the ability to self-upgrade to the latest versions. If the composer is already installed on your system, just type the below command to upgrade the PHP composer to the latest version.

    composer self-update
    

    In my case, I already have latest version of composer. So receive the following message on terminal:

    Output:
    You are already using the latest available Composer version 2.3.7 (stable channel).

    Working with PHP Composer

    You have already installed and configured the composer on your system. The composer will help you to manage modules for your application. For example, to install a new module for your application.

    Switch to the PHP application.

    cd /path/to/php-application 
    

    Run the following command to install psr/log module in the application.

    composer require psr/log
    
    Output:
    Using version ^3.0 for psr/log ./composer.json has been created Running composer update psr/log Loading composer repositories with package information Updating dependencies Lock file operations: 1 install, 0 updates, 0 removals - Locking psr/log (3.0.0) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Downloading psr/log (3.0.0) - Installing psr/log (3.0.0): Extracting archive Generating autoload files

    Composer will automatically create or update composer.json file at application root directory. Now, the application can use the functionality provided by the module.

    The above command will install the latest version of the module. You can also define the module version you want to install for your application. If the module is already installed, it will automatically downgrade/upgrade the package to the specified version.

    composer require psr/log=1.0
    

    The module no longer required can be removed with the following command.

    composer remove psr/log
    

    All the above commands also update composer.json file accordingly.

    Conclusion

    In this tutorial, you have found instructions to install composer on Ubuntu 22.04 (Jammy Jellyfish) system. You can install composer globally to allow access to all users and applications. Also, you can install composer for a specific directory.

    composer PHP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Create DMARC Record For Your Domain
    Next Article How to Install Angular CLI on Ubuntu 22.04

    Related Posts

    How to Install Apache Kafka on Ubuntu 22.04

    Updated:June 5, 20225 Mins Read

    Setting Up Environment Variables on Ubuntu

    Updated:May 28, 20222 Mins Read

    How to Install Apache Solr 9.0 on Ubuntu 22.04

    Updated:May 26, 20223 Mins Read

    How to Install .NET Core (dotnet) on Ubuntu 22.04

    Updated:May 25, 20224 Mins Read

    Changing the Login Screen Background in Ubuntu 22.04 & 20.04

    Updated:May 9, 20222 Mins Read

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:June 19, 20223 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • What is the /etc/aliases file
    • What is the /etc/nsswitch.conf file in Linux
    • How to Install Ionic Framework on Ubuntu 22.04
    • What is the /etc/hosts file in Linux
    • How to Install Angular CLI on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.