No image

How to install Composer on Ubuntu

All of our G3/G4/G5 Linux stacks already have Composer preinstalled. In a situation that composer is not installed on your stack, please contact support or follow the guidelines set here for proper installation.

Warning! Do NOT install composer 2.x for Magento. It will NOT work.

If you need to roll-back to an older version use:

sudo composer self-update 1.10.17

What is Composer? As Composer’s Official site states: “Composer is a tool 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.”

Why we use it? Magento CMS and Laravel uses it for updates and installs, and Magento: components, themes, and modules.

Composer Installation on aMiSTACX

~$ cd /home/ubuntu

~$ curl -sS -o composer-setup.php

[Optional] Verify that the installer matches the SHA-384 hash for the latest installer found on the Composer Public Keys / Signatures page. Copy this hash from that page, and declare it as a shell variable:

e.g. HASH=93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8

Composer Hash Value

[Optional] Now execute the following PHP script to verify that the Composer installation script is safe to run:

~$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Success shows the following output:
Installer verified

How do I install Composer programmatically?

Note: If you see Installer corrupt, then you’ll need to re-download the installation script again, and double-check that you’re using the correct hash. You also can also skip the verification steps too.

Next, to install Composer globally, use the following command which will download and install Composer as a system-wide command named Composer, under /usr/local/bin:

~$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

You’ll see the following output:

All settings correct for using Composer

Composer (version 1.7.3) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

To test Composer:

~$ composer

Composer test output on Ubuntu 18

To see composer in action please review our “Upgrade Magento 2 using Composer“.

Good to go!