Composer is a dependency manager for PHP that helps you manage libraries and packages in your PHP projects. To install Composer on Linux, you can follow these general steps. Please note that these instructions might need adjustments based on your specific Linux distribution.
1. Update Package Repositories:
Before installing any new software, it’s a good practice to update your package repositories.
sudo apt update
2. Install Required Dependencies:
Composer requires some dependencies to be installed. The following commands install these dependencies:
sudo apt install curl php-cli php-mbstring unzip
3. Download Composer:
You can download Composer using the following curl
command:
curl -sS https://getcomposer.org/installer -o composer-setup.php
4. Verify the Installer:
It’s a good practice to verify the integrity of the installer script. You can do this by comparing the hash of the downloaded installer with the one published on the Composer website.
HASH="$(curl -sS https://composer.github.io/installer.sig)"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
If the installer is verified, you will see “Installer verified.”
5. Install Composer:
Run the following command to install Composer globally:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
This command installs Composer in the /usr/local/bin
directory and names the executable file composer
.
6. Clean Up:
After installing Composer, you can remove the installer script:
rm composer-setup.php
7. Verify Installation:
To verify that Composer is installed successfully, run:
composer --version
You should see information about the installed Composer version.
That’s it! Composer should now be installed on your Linux system. Keep in mind that these instructions are general, and you may need to adapt them based on your specific Linux distribution or environment.