Get Started with Composer: A Complete Installation Guide

Prerequisites

Command Line Access
Composer needs an internet connection to download packages from the Packagist repository (or other configured repositories)
Composer is a PHP dependency manager, so PHP is required to run it
Git (optional but useful for package installation from repositories)

Introduction

If you're a PHP developer, managing dependencies and libraries efficiently is crucial to maintaining clean and scalable projects. This is where Composer, the most popular PHP dependency manager, comes into play. Composer simplifies the process of installing, updating, and managing third-party packages and libraries in your PHP projects.

In this guide, we'll walk you through the steps to get Composer up and running on your system. Whether you're using macOS, Linux, or Windows, we’ll cover the prerequisites, installation steps, and provide some tips for common troubleshooting along the way. By the end of this tutorial, you’ll have Composer installed and ready to streamline your PHP development workflow.

Let’s dive in and get Composer installed on your machine!

Install Composer on macOS

Open the terminal

Press Command + Space, type Terminal, and hit Enter.

Download the Composer installer

In your terminal, run the following command to download the Composer installer:

curl -sS https://getcomposer.org/installer | php

This command downloads and installs Composer as a composer.php file in your current directory.

Move Composer to a Global Location (Optional)

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

Verify Installation

composer --version

Install Composer on Linux

Before installing Composer, make sure PHP and curl are installed

For Ubuntu and other Debian-based distributions:

sudo apt update
sudo apt install php-cli php-mbstring unzip curl git

For CentOS 7 and older (using yum):

sudo yum install php-cli php-mbstring unzip curl git

For Fedora or CentOS 8 (using dnf):

sudo dnf install php-cli php-mbstring unzip curl git

dnf is the default package manager on Fedora, and newer versions of CentOS have moved to dnf as well

Download Composer Installer

curl -sS https://getcomposer.org/installer | php

Move Composer to a Global Location

Move the composer.phar file to a directory in your PATH so that you can access it globally:

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

Verify Installation

composer --version

Install Composer on Windows

Download the Composer Installer

Go to the official Composer website and download the Composer-Setup.exe file for Windows.

Run the Installer

Launch the Composer-Setup.exe file

Follow the prompts and make sure to select PHP executable during installation. If PHP is not already installed, the installer can help you install it.

Complete the Installation

Once the installation is finished, the Composer executable will be installed, and the installer will add it to your system's PATH.

Verify Installation

Open Command Prompt or PowerShell

  • Press Windows + R, type cmd, and hit Enter to open Command Prompt, or
  • Press Windows + X and choose Windows PowerShell to open PowerShell

Check Composer Version

In the terminal (Command Prompt or PowerShell), type the following command:

composer --version

If Composer is installed correctly, it will show you the version number, something like:

Composer version 2.8.5 2025-01-21 15:23:40

Final Thoughts

Congratulations! You’ve successfully installed Composer on your system and are now ready to take advantage of its powerful dependency management features. With Composer, you can easily manage PHP libraries, automate your workflows, and ensure that your projects stay organized and up-to-date. Whether you're working on a personal project or contributing to open-source software, Composer will become an invaluable tool in your development toolkit.

As you become more comfortable with Composer, explore its advanced commands and integrations, such as creating your own Composer packages and custom scripts. The more you dive into Composer, the more you'll unlock its potential to streamline your development process.

For more information on Composer, including advanced usage and tips, be sure to check out the official Composer website.

Happy coding, and enjoy the world of Composer!

Popular (all time)

Related articles

How to Edit Your WordPress Admin Username and Author Slug via MySQL

In this guide, we’ll walk you through the process of editing both the admin username and author slug using MySQL. Whether you’re looking to strengthen your site's security or simply personalize your author URL, this straightforward method will help you make the changes with ease.

Getting Started with React

In this guide, we will cover the basics of setting up a local development environment, starting a simple React project, and the basics of how it works.

How to Simplify Your Terminal with Custom Bash Aliases

By creating custom shortcuts for your most-used commands, you can save time, reduce errors, and make your terminal experience faster and more enjoyable. In this guide, we’ll show you how to create and manage your own Bash aliases to simplify your terminal workflow and boost your productivity.