How to install Composer using PowerShell without going crazy

Composer is a dependency manager for PHP. It helps us grab the right libraries (or “packages”) for a given project and makes sure they all play nicely together.

No more digging through GitHub repos or manually dragging .zip files around. It handles all that behind the scenes.

While Composer installation on Windows is supposed to be straightforward, it often proves otherwise.

Let’s see if we can make it simple.

Step-by-Step: Installing Composer Using PowerShell

First, open up Powershell as administrator (this is important).

Then:

1.    Download the Composer installer script.

Powershell command to download the Composer installer script
(click on the image to open in a new tab)

2. Verify the installer (optional, but considered good practice).

Powershell command to verify the Composer installer.
(click on the image to open in a new tab)

3. Install Composer.

Powershell command ot install Composer
(click on the image to open in a new tab)

4. Delete the installer.

Powershell command to delete the installer
(click on the image to open in a new tab)

Great! Now Composer is installed.

Success message of the Composer installation.
(click on the image to open in a new tab)

But we are not done just yet!

How to add the install directory to your system’s PATH

After installing, PowerShell might still display the error message composer is not recognized.

Error message that Composer is not recognized.
(click on the image to open in a new tab)

That’s because Windows doesn’t know where to find it.

We need to add the install directory to your system’s PATH

How you set your path and environment variables depends on your version of Windows. 

Let’s see how to do it in Windows 10. The process is similar in Windows 11.

  1. Press the Windows key and X to access the Power User Task Menu.
  2. Once in the Power User Task Menu, click System.

3. In the About window, find the Advanced system settings link in the Related settings section on the far right and click it.

4. To access Environment Variables, navigate to the System Properties window’s Advanced tab and click the button at the bottom.

5. In the System variables section of the Environment Variables window (below), highlight Path and click Edit.

6. Update the path lines to reflect the directories you want the computer to access.

Windows needs a restart after any environment variable changes to implement them.

Try:

composer --version

If you see a number version, everything works fine!

Composer command returns the latest Composer version.
(click on the image to open in a new tab)
NOTE: Sometimes Avast or another firewall might block PHP from making secure HTTPS requests. 

It’s not your fault;it’s your security software that’s causing the problem.

Try temporarily disabling it just to check.

Although my blog doesn’t support comments, feel free to reply via email or X.

Privacy Policy Lambros Hatzinikolaou © 2024 — Today. All rights reserved.