Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»MacOS»How to Install Composer on MacOS

    How to Install Composer on MacOS

    By RahulMay 21, 20223 Mins Read

    The PHP Composer is a package management tool. It removes the hassle of maintaining PHP packages for an application manually. You can easily install all the required packages using Composer. It maintains a list of required packages in a JSON file called composer.json.

    Advertisement

    This tutorial helps you to install and configure PHP composer on macOS operating system.

    install composer on macos

    1. Prerequisites

    • Shell access to a running macOS
    • PHP 5.3 or higher version must be installed

    2. Install Composer on macOS

    Download the composer binary file from the getcomposer.org website by running the following command. It will create a file named composer.phar in the current directory.

    curl -sS https://getcomposer.org/installer | php 
    

    Now, copy this composer.phar file under bin directory to make available anywhere in the system. Also, set the execute permission on file. I have changed the filename from composer.phar to composer for the easy use.

    mkdir -p /usr/local/bin 
    mv composer.phar /usr/local/bin/composer 
    chmod +x /usr/local/bin/composer 
    

    Run composer command on the command prompt. This will provide you with composer version details along with options available with the composer command.

    composer 
    
    
       ______
      / ____/___  ____ ___  ____  ____  ________  _____
     / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
    / /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
    \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                        /_/
    Composer version 2.3.5 2022-04-13 16:43:00
    
    Usage:
      command [options] [arguments]
    
    Options:
      -h, --help                     Display help for the given command. When no command is given display help for the list command
      -q, --quiet                    Do not output any message
      -V, --version                  Display this application version
          --ansi|--no-ansi           Force (or disable --no-ansi) ANSI output
      -n, --no-interaction           Do not ask any interactive question
          --profile                  Display timing and memory usage information
          --no-plugins               Whether to disable plugins.
          --no-scripts               Skips the execution of all scripts defined in composer.json file.
      -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
          --no-cache                 Prevent use of the cache
      -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
    

    3. Upgrade PHP Composer

    The PHP composer provides a command-line option (self-update) to upgrade itself. You can simply run the below command from the terminal to upgrade compose on your macOS.

    sudo composer self-update 
    

    4. Uninstall (Remove) PHP Composer

    As the composer is configured with a single file, you can simply remove it from your system.

    sudo rm /usr/local/bin/composer 
    

    Conclusion

    This tutorial helped you to install the PHP composer on the macOS system. That will help you to manage the dependencies of a PHP-based application.

    composer PHP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Installing PHP on Pop!_OS

    How to Install PHP 8.x on Pop!_OS

    Managing Dependencies with Composer: A Beginner’s Guide

    10 Simple Ways to Speed Up Your WordPress Website

    10 Simple Ways to Speed Up Your WordPress Website

    View 8 Comments

    8 Comments

    1. anon on December 9, 2021 7:16 pm

      thx

      Reply
    2. Max on January 28, 2021 12:47 pm

      Rahul, your name describes your way of updating composer. “Do not run Composer as root/super user! See https://getcomposer.org/root for details”

      Reply
    3. Anders Hellman on December 3, 2020 2:34 pm

      You also have to create the bin directory first. Like so:
      sudo mkdir /usr/local/bin
      Then
      sudo mv composer.phar /usr/local/bin/composer
      chmod +x /usr/local/bin/composer

      Reply
      • Happer64Bit on May 20, 2022 7:31 am

        You are right

        Reply
    4. Andrea on November 24, 2020 1:13 am

      You might have to create the /bin directory (If on Catalina)

      Reply
    5. Ayorinde Adunse on November 1, 2020 9:57 am

      Run using homebrew. Run the command brew install composer

      Reply
    6. MustafaH on January 6, 2020 2:34 am

      Thank you for information but I have a problem when installing composer.

      I’m using MacOS Catalina and when I try to use composer globally I can’t. I can’t move the phar file.

      Any suggestion?

      Thank you

      Reply
      • LEO on August 7, 2020 7:25 am

        You should use sudo mv composer.phar /usr/local/bin/composer

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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