How to Easily Install Composer on Mac OS Mojave

1 Star2 Stars3 Stars4 Stars5 Stars (9 votes, avr: 4.89)

A composer is a tool cross-platform for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

In this tutorial, you will learn how to easily install Composer on Mac OS and use it in your future PHP projects and add an alias so you can use it from anywhere. Simply follow this step by step guide.


Before starting with this guide, make sure you could access to the command line interface and know the root password of your Mac OS

Step 1: Download Composer

There are several ways to download a file called composer.phar. In this guide, we will use a script in order to automatically download the latest Composer version. From your terminal run the following command:

curl -sS | php

Or you can manually download a file composer.phar one here on Composer download page

Troubleshoot the Errors

In some cases, you might receive the following error:

Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The detect_unicode setting must be disabled.
Add the following to the end of your `php.ini`:
detect_unicode = Off

A php.ini file does not exist. You will have to create one.
If you can not modify the ini file, you can also run `php -d option=value` to modify ini values on the fly. You can use -d multiple times.

In the Mac OS X, the php.ini file should be located in /private/etc/.

If you don’t have one already, you can copy the default one:

sudo cp /private/etc/php.ini.default php.ini

Then, edit the file using nano editor:

sudo nano /private/etc/php.ini

And append the following to it

detect_unicode = Off

Press Ctrl/Cmd + X and then press Y and ENTER to save changes

Step 2: Install Composer Globally

We recommend making Composer accessible globally. This will ensure that Composer can be executed or accessible from anywhere on your system by simply typing composer. To do this, move it to /usr/bin/ and create an alias:

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

To create an alias we have to create or edit existing .bash_profile. To do this run the following command:

sudo nano ~/.bash_profile

Add or copy paste the following code

alias composer="php /usr/local/bin/composer.phar"

Press Ctrl/Cmd + X and then press Y and ENTER to save changes

Step 3: Running Composer

Now, relaunch your terminal can be executed or accessible Composer simply by calling composer. To run Composer, execute the command:


You should see an output similar to the below:

  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
Composer version 1.8.3 2019-01-30 08:31:33

  command [options] [arguments]

  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.

If this tutorial could help you, please rate above Star button rating and share to help others find it! Feel free to leave a comment below. If any others better Ideas I really appreciate it..

Recommended For You

About the Author: Adzan

Internet enthusiast like to share about newest information technology such as programming language, software developer and etc...