How to Install Composer on Ubuntu (24.04) for Easy Drupal Module & Theme Updates

| Servers | 11 seen

As a Drupal developer, keeping your modules up to date is crucial for security and performance. To streamline this process, I use Composer—a powerful dependency manager for PHP. It allows me to quickly update Drupal modules without the hassle of manually downloading and configuring each one. In this guide, I will walk you through the process of installing Composer on Ubuntu 24.04.

I typically run Drupal on an Ubuntu-based server with Nginx as the web server. This combination provides excellent performance and stability for hosting Drupal sites. Composer plays a crucial role in managing dependencies efficiently in this environment.

Composer is a dependency management tool for PHP that simplifies the installation and updates of libraries and packages. Instead of manually downloading and integrating each module, Composer automates the process, ensuring you always have the latest stable versions of your dependencies.

Step-by-Step Guide to Installing Composer on Ubuntu 24.04

1. Update Your System

Before installing any new software, ensure your system is up to date by running:

sudo apt update && sudo apt upgrade -y

2. Install Required Dependencies

Composer requires PHP and other dependencies. Install them using:

sudo apt install php-cli unzip curl -y

3. Download and Install Composer

Run the following commands to install Composer globally:

curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer

Alternatively, you can use the official installation method:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php php -r "unlink('composer-setup.php');"

Move Composer to a global location:

sudo mv composer.phar /usr/local/bin/composer

4. Verify Installation

After installation, verify that Composer is working by running:

composer -V

You should see the version number displayed, confirming a successful installation.

Using Composer for Drupal Module Updates

Once Composer is installed, updating Drupal modules becomes a breeze. Here’s how you can do it:

  1. Navigate to your Drupal project’s root directory:

    cd /path/to/your/drupal/site

  2. To update a specific module, run:

    composer update drupal/module_name --with-dependencies

  3. To update all modules and dependencies, use:

    composer update

  4. Clear the Drupal cache to apply updates:

    drush cache:rebuild

Using Composer simplifies Drupal module updates, ensuring you always have the latest security patches and features. With just a few commands, you can maintain your Drupal site efficiently and avoid potential compatibility issues. My usual setup involves Ubuntu with Nginx, and Composer integrates seamlessly into this environment, making dependency management straightforward.

Let me know in the comments if you have any questions or need further assistance.