How to install Composer on Ubuntu

Composer version verification 2.4.4

Composer and aMiSTACX

All of our G6 ~ G3 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.

Info! Do NOT install composer 2.x on pre 2.4.2 Magento OSE stacks.

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

sudo composer self-update 1.10.17

In situations where composer 2.x may error on new aMiSTACX stacks. [For whatever reason]

Some of our new migration stacks may have version 1.10.17 as default w/ 2.0.12 also installed. If you want/need 2.0.12:

You can switch to and from composer versions:

e.g. sudo composer self-update --rollback will take you back to 2.0.12

This may be required to update the aMiSTACX ModulerUpdater.

Once the aMiSTACX ModulerUpdater is updated, then you can switch back and forth between Composer versions.

Composer Install

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 Ubuntu

~$ cd /home/ubuntu

~$ curl -sS https://getcomposer.org/installer -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:

Output
All settings correct for using Composer
Downloading…

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

To test Composer:

~$ composer

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

Good to go!

Lead~Robot