Composer is a command-line package manager for the PHP programming language. Composer helps in managing dependencies and libraries that are required when developing PHP applications.
So if you’re developing a PHP app and you need some third-party libraries you can declare them in the “composer.json” file; while composer will go ahead to install the libraries and update them for you as necessary.
These packages are installed in a directory like “vendor within your project directory
Composer will manage the libraries of different PHP projects individually; because definitely different project need different packages or even none at all.
In this post, I would show you how you can install composer on Ubuntu Linux. Similar steps can be followed with other distros of Linux.
Requirements
For you to be able to run/use composer you must have PHP (version 5.3.2 and above) installed in your system.
Check here on how to install PHP on your system.
Step 1 – Update systems software repositories:
Use the command:
sudo apt-get update
Step 2 – Then go to the home directory:
cd ~
Step 3 – Download composer:
curl -sS https://getcomposer.org/installer -o composer-setup.php
Step 4 – Verify the installer
Now verify that the installer you just downloaded is the same with the latest version using the SHA-384 hash.
php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
If successful, you should have a “Installer verified” as output.
Step 5 – Install composer:
There are two ways to install Composer. Locally as part of your project, or globally as a system wide executable. Except on very important reasons, it is advisable to install it globally on your system. And thats what we will do here (i.e. In the /usr/local/bin directory);
sudo php composer-setup.php --install-dir=/usr/loacal/bin --finame=composer
The output should look like this;
All settings correct for using Composer
Downloading…
Composer (Version 1.8.6) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
You can type this command to launch composer:
composer
You should see this:
There you have it, composer installed in your system.
Happy Linux’NG!
- Time complexity analysis: How to calculate running time - April 1, 2024
- Sovereign Tech Fund Invests €1M In GNOME’s Open-Source Project - November 19, 2023
- Google’s Bard AI: ChatGPT Rival or The Next Frontier in AI and NLP Technology - February 8, 2023