How to install Composer on Ubuntu 22.04


How to install Composer on Ubuntu 22.04

Posted on 12th Apr 2025

A quick installation guide on how to install Composer for PHP on Linux Ubuntu 22.04

Install Composer on Ubuntu 22.04

To install Composer on Ubuntu 22.04, follow these steps:

  1. Refresh your system’s local package database by running sudo apt update to ensure your system is aware of the latest updates and versions of packages

  2. Upgrade the packages already installed on your machine by executing sudo apt upgrade to maintain your system’s stability and security

  3. Install the necessary packages that Composer depends upon. Use the following command to install php-cli, php-zip, and php-curl:

    sudo apt install php-cli php-zip php-curl
    
  4. Navigate to your home directory and download the Composer installer using the following command:

    curl -sS https://getcomposer.org/installer -o composer-setup.php
    
  5. Verify the integrity of the installation script by matching the hash of the downloaded file with the obtained hash. You can fetch the latest hash programmatically from the Composer page and store it in a shell variable:

    HASH=$(curl -sS https://composer.github.io/installer.sig)
    
  6. Execute the following PHP command to check if the installer 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;"
    
  7. If the output displays 'Installer verified', proceed to install Composer globally using the following command:

    sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
    
  8. To confirm that Composer has been installed correctly, run:

    composer --version
    

This verifies that Composer was successfully installed on your system and is available system-wide

Tags

installation guide composer php

Uploaded files
    No files found for this post.

copyright © 2025 Autonetix.co | Autonetix.au