Composer is a popular dependency manager used by web developers working with PHP frameworks like Laravel, Symfony, and CodeIgniter. It helps manage the packages needed to build web projects efficiently.
In this guide, we’ll show you how to install Composer on Ubuntu, starting from version 16.04 up to the latest 24.40.
Steps to Install Composer on Ubuntu
- Update Package Manager First, ensure your package manager is up to date. Open the terminal and run:
12345sudo apt update && sudo apt upgrade -y
- Install Required Dependencies Composer needs some dependencies to work properly. Install them by running:
12345sudo apt install curl php-cli php-mbstring git unzip -y
- Download Composer Installer After installing the dependencies, download the Composer installer with:
12345curl -sS https://getcomposer.org/installer -o composer-setup.php
- Install Composer To install Composer, run the following command:
12345sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- Verify Installation To confirm Composer is installed correctly, type:
12345composer
You should see an output similar to this:
123456789101112131415161718192021222324252627______/ ____/___ ____ ___ ____ ____ ________ _____/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___// /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /\____/\____/_/ /_/ /_/ .___/\____/____/\___/_//_/Composer version 2.4.4 2022-10-27 14:39:29Usage:command [options] [arguments]Options:-h, --help Display help for the given command. When no command is given display help for the list command-q, --quiet Do not output any message-V, --version Display this application version--ansi|--no-ansi Force (or disable --no-ansi) ANSI output-n, --no-interaction Do not ask any interactive question--profile Display timing and memory usage information--no-plugins Whether to disable plugins.--no-scripts Skips the execution of all scripts defined in composer.json file.-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.--no-cache Prevent use of the cache-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug - Add Vendor Directory to PATH To make Composer globally accessible, add the vendor directory to your PATH:
12345echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc && source ~/.bashrc
Now, Composer is ready to use for your web projects on Ubuntu.